JQuery popup problem
I work on Asp.Net VS08 C#. Clicking on Button want to show popup. popup contain a button ,Clicking on button perform serverside event but popup not close,popup close only click on cancel button .My problem is .i can call a popup but clicking on button not Perform server side event.
Aspx Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Popup3.aspx.cs" Inherits="Jquery1._8Version.Popup3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>&开发者_Go百科lt;/title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8rc2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8rc2.custom.min.js"></script>
<script type="text/javascript">
function openModalDiv(divname) {
$("#Popup").dialog({
bgiframe: true,
autoOpen: false,
height: 300,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
});
$("#Popup").dialog("open");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="Popup" style="display: none;" title="Basic dialog">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<input id="Button3" type="button" value="Open 1" onclick="javascript:openModalDiv('Popup');" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
C# code:
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
I think this is what you're after:
<script type="text/javascript">
$(function() {
$("#Popup").dialog({
bgiframe: true,
autoOpen: false,
height: 300,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
}).parent().appendTo($("form:first"));
$("#Button3").click() {
$("#Popup").dialog("open");
});
});
</script>
And just remove the onclick from the button, should be just this:
<input id="Button3" type="button" value="Open 1" />
The key part is this: .parent().appendTo($("form:first"))
. By default the modal is added to the body, which is outside the form. The result is that button data is never sent with the submit, and the server doesn't know the button was clicked, or to do anything. This tells the modal to hop right inside the end of the form. Try it, should resolve your issue.
精彩评论