The jQuery dialog box is rendered outside the form.
So you need to re-add the element to the form.
HTML
<div id="dialog" style="display: none">
This is a simple popup
<br />
<br />
<asp:TextBox ID="txt_name" runat="server"></asp:TextBox>
<asp:Button runat="server" Text="Submit" OnClick="OnSubmit" />
</div>
<asp:Button ID="btnPopup" runat="server" Text="Show Popup" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnPopup]").on("click", function () {
$("#dialog").dialog({
title: "jQuery Dialog Popup",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true,
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
return false;
});
});
</script>
Code
C#
protected void OnSubmit(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + txt_name.Text + "');", true);
}
VB.Net
Protected Sub OnSubmit(ByVal sender As Object, ByVal e As EventArgs)
ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", "alert('" & txt_name.Text & "');", True)
End Sub
Screenshot