I have server side event like this.
protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
{
// implementation here.
}
I am trying to call it from client side javascript. I have tried __doPostBack("contextMenuItemID", "some string")
it posts the page back to server, but this does not invoke the original ContextMenuItemClick event. How can I invoke the original contextMenuItemClick event with proper event Args?
This method is used to submit (post back) a form to the server and allows ASP.NET framework to call appropriate event handlers attached to the control that raised the post back.
In order to call a Server Side function from JavaScript, it must be declared as static (C#) and Shared (VB.Net) and is decorated with WebMethod attribute. Then the Server Side method can be easily called with the help of ASP.Net AJAX PageMethods and JavaScript without PostBack in ASP.Net.
In web development, a postback is an HTTP POST to the same page that the form is on. In other words, the contents of the form are POSTed back to the same URL as the form. Postbacks are commonly seen in edit forms, where the user introduces information in a form and hits "save" or "submit", causing a postback.
How to Raise a Postback from JavaScript? To do this, we need to just call the __doPostBack() function from our javascript code. When the above function is called, it will raise a postback to server.
You'll want to look at using the ClientScriptManager.GetPostBackEventReference method. This will create the correct javascript call ("__doPostBack") for the control/action using the ClientScriptManager (untested example):
<script type="text/javascript">
function callPostBack() {
<%= Page.ClientScript.GetPostBackEventReference(RadTreeView1, String.Empty) %>;
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With