Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have been struggling with this for a while now, so was hoping someone might be able to help me out. I have basically copied the source of this page: http://jqueryui.com/demos/dialog/#modal-form into two different aspx pages, one standard one, and one that uses a masterpage. The "normal" page one works perfectly, but on the masterpage, the button here:
<button id="create-user">Create new user</button>

immediately posts back when you click it, meaning obviously that the modal dialog never appears (or appears briefly before the page reposts). I cannot for the life of me work out why the masterpage would affect this. Both pages have the exact same code, with nothing extra (and nothing whatsoever in the code-behind), except what's in the masterpage, which of course includes this:
<script type="text/javascript" src="/JS/jquery-1.4.2.min.js"></script>
   <script type="text/javascript" src="/JS/jquery-ui-1.8.4.custom.min.js"></script>


I tried changing this:
$('#create-user')
            .button()
            .click(function () {
                $('#dialog-form').dialog('open');
            });



to this (to take into account the renaming of clientIDs by the masterpage):
$('#ctl00_ContentPlaceHolder1_create-user')
            .button()
            .click(function () {
                $('#dialog-form').dialog('open');
            });



but to no avail, the button still posts back instantly whenever I click it. I know I can stop this with return:false; but I eventually want to run eventhandler code from it...

Does anyone know why this is happening? I want to use JQuery (which I'm new to) in my project, but if I cannot even get a copy/paste of the demo to work, it doesn't bode too well....
Posted
Updated 7-Sep-10 6:28am
v2

use Return false from the click handler to ensure that the button never generates the Postback.

I would also recommend you to avoid using runat=server if you want your button to never postback.
 
Share this answer
 
Comments
AspDotNetDev 7-Sep-10 12:39pm    
1) The OP specifically states that the "return false" can be done but that he/she wants to know why there is a difference.

2) The code sample clearly shows there is no "runat=server".
Seems the default behavior for the "button" tag differs between browsers. Maybe the HTML is slightly different (e.g., whitespace before the HTML tag) so you are getting compatibility mode in IE in some cases. Read about this possiblity here: http://www.w3schools.com/tags/tag_button.asp

I didn't even know there was an HTML button tag. I usually use an input tag with the attribute set to "button" whenever I want a button that doesn't cause a postback. Give that a try (i.e., use an input tag rather than a button tag).
 
Share this answer
 
Thanks for this. I gave it a try, but no luck... the input button does nothing at all, doesn't even run the jquery code. To be honest though, I want the button to have a postback, but for the jquery to call it once the button in the modal popup is clicked - looking at the documentation this is how I understand it's supposed to work..

Interestingly I was using Firefox, and when I tried it IE8 just now, it worked perfectly... It's a sorry state of affairs when things work properly in IE and not in Firefox!

Now that I know it's a browser thing, I'll keep looking for answers on Google though (but if anyone has any ideas, please let me know!)


ok, I just did another hunt around on Google, and came across this: http://www.integratedwebsystems.com/2009/12/using-jquery-modal-dialog-confirmation-with-an-asp-net-server-control/. I copied his code and it worked perfectly in IE and Firefox. Not sure what was wrong with the demo code, but as this now works, I will use this as the template from which to create the actual code for my project.

It looks like this is the line I needed: <![CDATA[<%=this.Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this.Button1)) %>;%>]]>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900