Skip to main content Skip to footer

Postback using controls placed in C1Dialog

A customer came to us with requirement of firing a 'PostBack' on clicking button present inside C1Dialog. This sounds really easy. However on trying the same one will be really amazed to see that 'PostBack' just not happen while clicking the button. So I researched a bit on what might be the reason behind this. I would like to share my findings in this blog. Reason and Solution - 'PostBack' does not happen because jQuery append dialog to the document body outside of the form. In order to have a succesful 'PostBack' it is necessary to add C1Dialog inside the form rather than the document body. I have attached a sample along with the post to illustrate the same. It contains C1Dialog with a textbox and a button control. Run the website and Click button 'Click Me'. You will notice no postback happens. Now stop the application and follow steps below - 1) Comment code <asp:Button ID="Button2" runat="server" Text="Click Me!" /> 2) Uncomment code <asp:Button ID="Button1" runat="server" Text="Click Me!" OnClientClick= "forPostback()" /> Again run the website and Click button 'Click Me'. On clicking button successful PostBack will be seen. This time OnClientClick event we called function "forPostback()" in order to fire the same. function forPostback() { $("#C1Dialog1").parent().appendTo($("form:first")) // Move dialog inside of Form to ensure PostBack } The above function adds C1Dialog inside the form rather than the document body. Here is the attached sample ASPC1Dialog_PostBack Hope this post helps incase anyone is encountering issue while firing a PostBack with controls inside C1Dialog. Regards Palak

MESCIUS inc.

comments powered by Disqus