Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jquery Dialog Form

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have the following code which opens up a form in a jquery dialog.

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="dialog.aspx.vb" Inherits="dialog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
    <title></title>
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/ui-darkness/jquery-ui.css" rel="stylesheet">
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
</head>
<body>
<form runat="server">
    <div id="dialog" title="Dialog">
		
        
        <table>
        <tr>
        <td>Name:</td>
        <td></td>
        </tr>
            
        <tr>
        <td>Email Address:</td>
        <td></td>
        </tr>
        
        
        </table>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        




	</div>
    <input type="button" id="button" value="Click to open the dialog">
	<script>
	   
	    $(function () {
	        $("#dialog").dialog({
	            autoOpen: false
	        });
	        $("#button").on("click", function () {
	            $("#dialog").dialog("open");
            
	        });

	    });
	</script>
    </form>
</body>
</html>

I have some .net code on the Button1 which adds a new record to the database, however whenever I click on the button it doesn't fire the event.

Also I need it to close the dialog form as well.

Any ideas.
Thanks
Andrew
 
I think that may be old jquery syntax.
Try
Code:
$("#button").click(function () {
  $("#dialog").dialog("open");
});
 
Humm, ok not old syntax... my bad
put the script at the top of the page and try it.
 
it looks like the jquery selector is looking for an element with the id "button", but the actual element's id is "Button1".

good luck!

-Mark
 
Hi, thanks for your help.

I managed to get it working with

Code:
<script type="text/javascript">
	    $(document).ready(function () {
	        $("#dialog").dialog({ autoOpen: false, modal: true, width: '400px', title: "Add New Item"  })
	        $("#AddNew").click(function () {
	            $("#dialog").dialog('open');
	            return false;
	        });

	        $('#<%= AddNewButton.ClientID %>').click(function () {
	            __doPostBack('<%= AddNewButton.ClientID %>', '');
                $("#dialog").parent().appendTo(jQuery("form:first"));
	            $("#dialog").dialog('close')
	        });
	    });
</script>
 
Any idea why the code on my button would be firing twice.

I have code that inserts a record into a table and it adds the record twice.
 
I would imagine it's because you are manually triggering a postback. An asp.net button, by default, already triggers a postback.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top