views:

1058

answers:

5

I have several small divs which utilizing jQuery draggable. These divs are placed in an update panel, 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.

Any help would be much appreciated.

Thanks, Shawn

A: 

You can't call _doPostBack() because it forces submition of the form. Why don't you disable the post back on the update panel?

Alex
I need the update panel for the AJAX.
ErnieStings
A question. When a div is dragged the _doPostBack is invoked by you or automatically by ASP.NET?
Alex
it is invoked by me via javascript
ErnieStings
A: 

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.

Phairoh
what's the first most evil thing that microsoft created for web developers?
ErnieStings
the login control must be pretty high up that list.
kim3er
@ErnieStings: IE6
Phairoh
+1  A: 

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.

__doPostBack(UpdatePanelClientID, '**Some String**');
Jeremy Bade
A: 

While Phairoh's solution seems theoretically sound, I have also found another solution to this problem. By passing the UpdatePanels id as a paramater (event target) for the doPostBack function the update panel will post back but not the entire page.

__doPostBack('myUpdatePanelId','')

*note: second parameter is for addition event args

hope this helps someone!

EDIT: so it seems this same piece of advice was given above as i was typing :)

ErnieStings
This will work, and I have done something similar in an application, but it is really not a good idea and I hate that I had to do it when I did. If your update panel's name ever changes, it breaks. If you ever put this inside a user control, it breaks. If you add a masterpage, it breaks. Yes it works, but it's quite fragile. At the very least, please use the ClientId property of your update panel instead of the static string.
Phairoh
A: 

Per Phairoh: Use this in the Page/Component just in case the panel name changes

<script type="text/javascript">
     <!--
     //must be global to be called by ExternalInterface
         function JSFunction() {
             __doPostBack('<%= myUpdatePanel.ClientID  %>', '');
         }
     -->
     </script>
Laramie