locked
Persist data inside Modalpopupextender RRS feed

  • Question

  • User1909155429 posted


    I have the following code and I want to persist data inside each textbox control when Cancel button is activated?

    <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>
                                                                 
          
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th>
                                                            City/Town:
                                                        </th>
                                                        <td>
                                                            <asp:TextBox ID="TxtCity" runat="server" MaxLength="20"></asp:TextBox>
                                                                    
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <th>
                                                            Region:
                                                        </th>
                                                        <td>
                                                            <asp:TextBox ID="TxtRegion" runat="server" MaxLength="30"></asp:TextBox>
                                                                                
              
    
                                                        </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>
              
            
             
                 <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderAddress" runat="server"  BackgroundCssClass="modalBackground"   
                                             CancelControlID="BtnCancel" DropShadow="true" 
                                            OkControlID="BtnClose" OnCancelScript="CanAddress()" OnOkScript="performCheck()" PopupControlID="PnlAddress" 
                                            TargetControlID="AddressChange" />

    Thursday, January 12, 2017 6:39 PM

All replies

  • User-271186128 posted

    Hi peterthegreat,

    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

    Monday, January 16, 2017 3:10 AM