I am working on an asp.net application. I am using Jquery UI to add record to database. here is the markup.
<div id="AddShippingPopup" class="popup" title="New Shipping Address">
<p>Shipping Address</p>
<table>
<tr>
<td> Line 1:</td>
<td><asp:TextBox ID="txtShippingLine1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Line 2:</td>
<td><asp:TextBox ID="txtShippingLine2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>City:</td>
<td> <asp:TextBox ID="txtShippingCity" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>State:</td>
<td> <asp:DropDownList ID="ddlShipingState" runat="server" Width="200px" CssClass="required">
<asp:ListItem Value="">Please select</asp:ListItem>
<asp:ListItem Value="AK">Alaska</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td>Zip:</td>
<td><asp:TextBox ID="txtShippingZip" runat="server" Width="50px"></asp:TextBox></td>
</tr>
<tr>
<td>Preferred:</td>
<td>
<asp:CheckBox ID="chkPreferredShipAdd" runat="server" />
</td>
</tr>
</table>
</div>
and here is a button outside this div:
<asp:Button ID="btnAddShipping" runat="server" Text="Add Shipping" style = "display:none" OnClick = "btnAddShipping_Click" />
and Jquery dialog code:
$("#AddShippingPopup").dialog({
autoOpen: false,
modal: true,
width: 500,
height: 370,
buttons: {
"Cancel": function () {
$(this).dialog("close");
},
"Save": function () {
$("[id*=btnAddShipping]").click();
$(this).dialog("close");
}
}
});
function createShippingAddress() {
$("#AddShippingPopup").dialog("widget").find(".ui-dialog-titlebar-close").hide();
$("#AddShippingPopup").dialog("open");
return false;
}
and here is link to initialize the dialog:
<asp:LinkButton ID="lnkAddNewShippingAddress" runat="server" Font-Size="Smaller" OnClientClick="createShippingAddress(); return false;">Add New</asp:LinkButton>
but values of text boxes and drop down are empty when Save button is clicked. and empty strings are saved in db. How to fix it ?
The usual problem in this cases is that the javascript Dialog . 。
So force him to render inside the form by using the appendTo
option. Here is an example from jQuery site :
$( ".selector" ).dialog({ appendTo: "#someElem" });
and be sure that the element that you append to, is inside your asp.net form.
Your code will be as:
$("#AddShippingPopup").dialog({
appendTo: "#dialogAfterMe",
autoOpen: false,
modal: true,
width: 500,
height: 370,
buttons: {
"Cancel": function () {
$(this).dialog("close");
},
"Save": function () {
$("[id*=btnAddShipping]").click();
$(this).dialog("close");
}
}
});
and place this div somewhere inside your form
<div id="dialogAfterMe"></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.