__doPostBack reloading entire page instead of just

2019-06-28 06:49发布

问题:

In my javascript, I have the following line:

__doPostBack('MyPanel', MyParam);

In my code behind, I use MyParam to query a database and bind the result to a gridview that's inside the MyPanel updatepanel. The updatemode of the updatepanel is set to conditional and in the postback part of the code I have MyPanel.Update();

The updatepanel works fine when I'm doing sorting and paging; only the panel is refreshed. However, when I trigger the updatepanel with my javascript, I see the traffic in firebug showing that the entire page is being refreshed.

What's the solution?

Thanks.

回答1:

My assuption: your update panel is located inside the naming container, so its id in the client side will be a little bit different from the server side ID. This means you pass the wrong __EVENTTARGET parameter to the client side __doPostBack function and your partial postback became full(meaning not async).

So changing your client code to:

__doPostBack('<%= MyPanel.ClientID %>', MyParam);

should solve the problem.

BTW, you could get the second(MyParam in your code) parameter from the server side:

var arg = Request.Params.Get("__EVENTARGUMENT");