Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to call server side event using __doPostBack

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?

like image 370
Manas Saha Avatar asked May 07 '12 13:05

Manas Saha


People also ask

What does__ doPostBack do?

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.

How do you call a Server Side function?

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.

What is do postback?

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 force postback in JavaScript?

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.


1 Answers

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>
like image 121
CAbbott Avatar answered Oct 02 '22 00:10

CAbbott