locked
asp textbox in jquery popup is returning null RRS feed

  • Question

  • User751067116 posted

    HI all,

     I have a text box in juery pop up after clicking on a button i was trying to save the value in text box to db using c#  but the textbox is retuning null value . somebody please respond to this issue

    Saturday, December 6, 2014 3:54 AM

Answers

  • User541108374 posted

    Hi,

    try to put the information in a hidden field outside of the popup in the form that you're submitting to the server just before the popup gets closed.

    Also, make use of the F12 tools of your browser to inspect the value of the textbox after it's been filled in and again after the popup has been closed. Likely the closing of the popup has destroyed the value of the textbox somehow.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 6, 2014 7:49 AM
  • User-271186128 posted

    Hi Jayadeep,

    As XIII said, you could use a hidden field. please refer to the following code.

        <form id="form1" runat="server">
            <h2 class="demoHeaders">Dialog</h2>
            <p><a href="#" id="dialog-link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a></p>
    
            <div id="dialog" title="Dialog Title">
                <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
                <asp:Button runat="server" ID="btnGetName" Text="GetName" OnClick="btnGetName_Click" />
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
            </div>
            <asp:Label runat="server" ID="lblMessage" Text=""></asp:Label>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
        <script src="external/jquery/jquery.js"></script>
        <script src="jquery-ui.js"></script>
        <script>
            $("#dialog").dialog({
                autoOpen: false,
                width: 400,
                buttons: [
                    {
                        text: "Ok",
                        click: function () {
                            var str = $("#txtName").val();
                            $("#HiddenField1").val(str);
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "Cancel",
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
    
            // Link to open the dialog
            $("#dialog-link").click(function (event) {
                $("#dialog").dialog("open");
                event.preventDefault();
            });
        </script>

    Code Behind.

            protected void Button1_Click(object sender, EventArgs e)
            {
                lblMessage.Text = HiddenField1.Value;
            }

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 8, 2014 3:46 AM

All replies

  • User541108374 posted

    Hi,

    try to put the information in a hidden field outside of the popup in the form that you're submitting to the server just before the popup gets closed.

    Also, make use of the F12 tools of your browser to inspect the value of the textbox after it's been filled in and again after the popup has been closed. Likely the closing of the popup has destroyed the value of the textbox somehow.

    Grz, Kris.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 6, 2014 7:49 AM
  • User-271186128 posted

    Hi Jayadeep,

    As XIII said, you could use a hidden field. please refer to the following code.

        <form id="form1" runat="server">
            <h2 class="demoHeaders">Dialog</h2>
            <p><a href="#" id="dialog-link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-newwin"></span>Open Dialog</a></p>
    
            <div id="dialog" title="Dialog Title">
                <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
                <asp:Button runat="server" ID="btnGetName" Text="GetName" OnClick="btnGetName_Click" />
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
            </div>
            <asp:Label runat="server" ID="lblMessage" Text=""></asp:Label>
            <asp:HiddenField ID="HiddenField1" runat="server" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </form>
        <script src="external/jquery/jquery.js"></script>
        <script src="jquery-ui.js"></script>
        <script>
            $("#dialog").dialog({
                autoOpen: false,
                width: 400,
                buttons: [
                    {
                        text: "Ok",
                        click: function () {
                            var str = $("#txtName").val();
                            $("#HiddenField1").val(str);
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "Cancel",
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
    
            // Link to open the dialog
            $("#dialog-link").click(function (event) {
                $("#dialog").dialog("open");
                event.preventDefault();
            });
        </script>

    Code Behind.

            protected void Button1_Click(object sender, EventArgs e)
            {
                lblMessage.Text = HiddenField1.Value;
            }

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 8, 2014 3:46 AM