Click here to Skip to main content
15,900,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a jquery code which is intended to be called by an ASP Button click,it works on button click but the problem is ,when called , the page is loaded even though it is not given in the page load event. I give the jQuery here please see it and give me your suggestion

Thanks in advance

HTML
<script type="text/javascript">

$(function() {

        $('#openDialog').click(
            $(function() {
                
                $("#dialog").dialog();
            }
            ));

    });

</script>


ASP.NET
<asp:Button ID="openDialog" runat="server" Text="Submit" CssClass="myButton"  />


XML
<div id="dialog" title="BasicDialauge">


            <p >This is chek for dialouge box</p>
            </div>
Posted
Updated 11-Jun-14 5:36am
v2

1 solution

You have an extra $(...) wrapping your click event handler.

Try this:
JavaScript
$(function() {
    $('#openDialog').click(function() {
        $("#dialog").dialog();
        return false;
    });
});

Edit: You'll need to add return false; to cancel the click event so that the page doesn't post back to the server. (Thanks to Member 10272815!)
 
Share this answer
 
v2
Comments
rajeeshsays 11-Jun-14 12:08pm    
I have tried with the code suggested by you,it dialog box doesnt open when the page is loaded that was my first problem it solved thanks for that ,but when the button is clicked dialog box is opened and suddenly closed,it is closed automatically I need it be stayed open until I close it
Member 10272815 11-Jun-14 12:26pm    
Sounds like your asp:Button is the problem then - they're submit buttons and when clicked post the page back to the server. You need to cancel the form submission by either returning false or the result of $("#dialog").dialog (assuming it returns a true/false) from your click function.
rajeeshsays 11-Jun-14 12:36pm    
My heartfull thanks for this replay.My prayers

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