Monday, July 2, 2012

Asp.net jQuery Dialog buttons do Post back using UseSubmitBehavior


When you display a DIV tag with Asp.Net server side controls, in a jQuery Dialog the server side events will get disabled and the events will not get fired, this happens because the controls are moved out of the form to display them as a Dialog box.

If you want the fire the click events of the buttons in the Dialog, we can do so by setting the
usesubmitbehavior property of the button to false.


<asp:Button ID="cmdSave"
runat="server"
Text="Save"
usesubmitbehavior="false"
      onclick="cmdSave_Click" />

By default this property is set to true, hence the button will depend on the forms submit mechanism to trigger the post-back, when the value is set to false, Asp.Net adds custom code to trigger the buttons postback, without depending on the forms submission.

One drawback of this approach is that the values of the controls in the div tag will not be available in the code-behind, as we are just triggering a post-back and not actually submitting the form, if you want the updated values of the controls to be available in the code-behind then you have to add the elements back to the form, refer the post  Asp.net jQuery Dialog control events not firing to see on how this can be achieved.






Related Post

Search Flipkart Products:
Flipkart.com

No comments: