I have several small div
s which utilizing jQuery
draggable. These div
s are placed in an UpdatePanel
, and on dragstop I use the _doPostBack()
JavaScript function. where i extract necessary information from the pages form.
My problem is that when i call this function the whole page is re-loaded but i only want the update panel to be re-loaded.
First, don't use update panels. They are the second most evil thing that Microsoft has ever created for the web developer.
Second, if you must use update panels, try setting the UpdateMode property to Conditional. Then add a trigger to an Asp:Hidden control that you add to the page. Assign the change event as the trigger. In your dragstop event, change the value of the hidden control.
This is untested, but the theory seems sound... If this does not work, you could try the same thing with an asp:button, just set the display:none style on it and use the click event instead of the change event.
You can't call
_doPostBack()
because it forces submition of the form. Why don't you disable thePostBack
on theUpdatePanel
?Here is a complete solution
Entire form tag of the asp.net page
Entire Contents of the Page's Code-Behind Class
What's going on?
Two input controls are rendered to the client:
__EVENTTARGET
receives argument 1 of __doPostBack__EVENTARGUMENT
receives argument 2 of __doPostBackThe __doPostBack function is rendered out like this:
When the form submits / postback occurs:
javascript:__doPostBack('ButtonB','')
, then the button click handler for that button will be run.What if I don't want to run a click handler, but want to do something else instead?
You can pass whatever you want as arguments to
__doPostBack
You can then analyze the hidden input values and run specific code accordingly:
Other Notes
ClientIDMode="Static"
, then you can do something like this:__doPostBack('<%= myclientid.UniqueID %>', '')
.__doPostBack('<%= MYBUTTON.UniqueID %>','')
Have you tried passing the Update panel's client id to the __doPostBack function? My team has done this to refresh an update panel and as far as I know it worked.
Per Phairoh: Use this in the Page/Component just in case the panel name changes
Using
__doPostBack
directly is sooooo the 2000s. Anybody coding WebForms in 2018 uses GetPostBackEventReference(More seriously though, adding this as an answer for completeness. Using the
__doPostBack
directly is bad practice (single underscore prefix typically indicates a private member and double indicates a more universal private member), though it probably won't change or become obsolete at this point. We have a fully supported mechanism in ClientScriptManager.GetPostBackEventReference.)Assuming your btnRefresh is inside our UpdatePanel and causes a postback, you can use GetPostBackEventReference like this (inspiration):