I have the following code and I want to persist data inside each textbox control when Cancel button is activated?
Based on your code, I create a sample, it seems that everything works well, when I click the cancel button and reopen the Popup Modal, the values are not disappear.
I suggest you could try again.
If still not working, I suggest you could add some hidden fields to store the entered values. Code as below:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
//cancel evnet
function CanAddress() {
//find all of the texbox and assign its value to hiddenfild
$("#address input[type='text']").each(function () {
var value = $(this).val();
if (value.length > 0) {
$(this).next("input[type='hidden']").val(value+"$");
}
});
};
function performCheck() {
alert("OK");
};
$(function () {
//find all of the hidden field and assign its value to textbox.
$("#AddressChange").click(function () {
$("#address input[type='hidden']").each(function () {
var value = $(this).val();
if (value.length > 0) {
$(this).prev("input[type='text']").val(value);
}
});
});
});
</script>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<div>
<asp:Button ID="AddressChange" runat="server" Text="Address" />
<asp:Panel ID="PnlAddress" runat="server" align="center" Style="display: none" CssClass="modalPopup">
<h2 id="PopupHeader" class="PopupHeader">Item address location</h2>
<table id="address" border="0">
<tr>
<th>Street Address:
</th>
<td>
<asp:TextBox ID="TxtAddress" runat="server" MaxLength="100"></asp:TextBox>
<asp:HiddenField ID="HiddenField1" runat="server" Value="" />
</td>
</tr>
<tr>
<th>City/Town:
</th>
<td>
<asp:TextBox ID="TxtCity" runat="server" MaxLength="20"></asp:TextBox>
<asp:HiddenField ID="HiddenField2" runat="server" Value="" />
</td>
</tr>
<tr>
<th>Region:
</th>
<td>
<asp:TextBox ID="TxtRegion" runat="server" MaxLength="30"></asp:TextBox>
<asp:HiddenField ID="HiddenField3" runat="server" Value="" />
</td>
</tr>
<tr class="Controls">
<td>
<asp:Button ID="BtnClose" runat="server" Text="Finish"
ValidationGroup="ADDRESS" /></td>
<td>
<asp:Button ID="BtnCancel" runat="server" Text="Cancel" /></td>
</tr>
</table>
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtenderAddress" runat="server" BackgroundCssClass="modalBackground"
CancelControlID="BtnCancel" DropShadow="true"
OkControlID="BtnClose" OnCancelScript="CanAddress()" OnOkScript="performCheck()" PopupControlID="PnlAddress"
TargetControlID="AddressChange" />
</div>
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
288 Points
890 Posts
Persist data inside Modalpopupextender
Jan 12, 2017 06:39 PM|peterthegreat|LINK
I have the following code and I want to persist data inside each textbox control when Cancel button is activated?
All-Star
45489 Points
7008 Posts
Microsoft
Re: Persist data inside Modalpopupextender
Jan 16, 2017 03:10 AM|Zhi Lv - MSFT|LINK
Hi peterthegreat,
Based on your code, I create a sample, it seems that everything works well, when I click the cancel button and reopen the Popup Modal, the values are not disappear.
I suggest you could try again.
If still not working, I suggest you could add some hidden fields to store the entered values. Code as below:
Best regards,
Dillion