1

I want to store TextBox value in HidenField and i am calling javascript function on button click function is calling getting message Hi but... textBox getting null....I am using asp.net TextBox and also i have tried with HTML textBox also but same scenario happing in both the case...Actually HTML code using in Ajax Tab Container may be this problem ... How to solve such type of problem

function f11() {
    alert("Hi")
    alert("hi..." + document.getElementById("txthtmltextbox").value)
    document.getElementById("txtuncheaderHF").value = document.getElementById("txthtmltextbox").value;
    document.getElementById("txtrootFolderHF").value = document.getElementById("txthtmltextboxroot").value
}

This is my HTML code

<asp:Panel ID="pnlhfconfig" runat="server" Height="100%" Width="100%">
    <table bordercolor="gainsboro" bgcolor="white" style="border-bottom-width: 1px; border-bottom-style: solid;
        border-top-width: 1px; border-top-style: solid; border-left-width: 1px; border-left-style: solid;
        border-right-width: 1px; border-right-style: solid; border-bottom-color: #8C8B83;
        border-top-color: #8C8B83; border-left-color: #8C8B83; border-right-color: #8C8B83;"
        id="TABLE2" language="javascript">
        <tbody>
            <tr>
                <td colspan="3" bgcolor="#E5E5E5" height="20" class="topnav" style="font-size: 10px;
                    font-family: verdana">
                    <font style="color: #000000"><strong>
                        <asp:Literal ID="Literal4" runat='server' Text='HF Configuration'></asp:Literal>&#160;&#160;</strong></font>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbluncheader" runat="server" Text='HotFolder UNCHeader'></asp:Label>
                </td>
                <td>                                                                                                                                                                  
                    <input type="text" id="txthtmltextbox" name="txthtmltextbox" onblur="f1()" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />

                        <asp:RequiredFieldValidator ID="rfvuncheader" runat="server"
                            ErrorMessage="UNCHeader is required." ControlToValidate="txthtmltextbox" Display="None"
                            ValidationGroup="save"></asp:RequiredFieldValidator>

                </td>
                <td>
                    <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblrootfolder" runat="server" Text='Hot RootFolder'></asp:Label>
                </td>
                <td>

                <input type="text" id="txthtmltextboxroot" name="txthtmltextboxroot" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />

                   <%-- <asp:TextBox ID="txtrootfolder" runat="server" MaxLength="50" Width="250px"></asp:TextBox>--%><asp:RequiredFieldValidator
                        ID="rfvUNH" runat="server" ErrorMessage="RootFolder is required." ControlToValidate="txthtmltextboxroot"
                        Display="None" ValidationGroup="save"></asp:RequiredFieldValidator>


                </td>
                <td>
                    <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <table>
                        <tr>
                            <td>
                            <asp:Button ID="btnsave" OnClientClick ="f1()"   runat="server" Text='Save' Width="55px" BackColor="#E5E5E5"
                                    ForeColor="Black" ValidationGroup="save" />


                            </td>
                            <td>
                                <asp:Button ID="btncancel" runat="server" Text='Cancel' Width="55px" BackColor="#E5E5E5"
                                    ForeColor="Black" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                                    ShowSummary="False" ValidationGroup="save" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
</asp:Panel>
4
  • Can you post the generated HTML? Commented Jan 10, 2014 at 4:17
  • it happens due to post back....post back causes the page to refresh Commented Jan 10, 2014 at 4:17
  • try adding a return false in your f11 function at the end Commented Jan 10, 2014 at 4:18
  • no change after adding return false Commented Jan 10, 2014 at 4:38

2 Answers 2

2

Hope you aware of JQuery and using JQuery, you will easily get inner control of panel. Because when your page is render on browser. Html code is something different then .NET(ASPX page).

You will get/set panel inner control value using below statement.

$("#<%=pnlhfconfig.ClientID %> input[id='<%= txtuncheaderHF.ClientID %>']").val($("#<%=pnlhfconfig.ClientID %> input[id='<%= txthtmltextbox.ClientID %>']").val());
Sign up to request clarification or add additional context in comments.

Comments

0

You are using txthtmltextbox please check on console what is the actual ID of control while generating html.

Or use as

 document.getElementById("<%= txthtmltextbox.ClientID%>").value

3 Comments

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)...Getting Error in Mozilla 26.0
I was miss " please try now
same Error after adding Quoation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.