0

In my project i need change visible of dynamic asp control when click label based on textbox values. So i first tried to get textbox value when click label but its return undefined. I am search and get two methods i tried that also it return same.

My Try :

        <script language="javascript" type="text/javascript">

                  $(document).ready(function() {

                      $(document).on("click", "#lblShow", function() {

                      alert($('#<%=txtTotalVersion.ClientID%>').val());

                       alert($('input[id$=txtTotalVersion]').val());

                      var xTotlal =$('#<%=txtTotalVersion.ClientID%>').val()
                          var i = 0;
                       for (i = 0; i < xTotlal; i++) {

                              $('#createDiv' + i).style.display = "blcok";
                              $('#createDiv1' + i).style.display = "block";
                              $('#createDiv2' + i).style.display = "block";
                              $('#createDiv3' + i).style.display = "block";
                          }

                      });

                  });

              </script>

HTML

   <div id="DivCompName">
         <asp:TextBox runat=server ID="txtTotalVersion" Visible="false"></asp:TextBox>
         <asp:TextBox runat=server ID="txtCurrentDisplay" Visible="false"></asp:TextBox>
      </div>

First two alert return undefined.

2 Answers 2

1

Visible="false" is asp.net attribute, in this case your control will not be rendered at the client side. So your client script won't find the control as it doesn't exists!

If you want to store some value at client side and don't want to display it then you can use HiddenFields or you can make the same control hidden by using css style display:none;. (Don't use Visible="false" for this)

Sign up to request clarification or add additional context in comments.

Comments

0

you can add ClientIDMode=Static and call it from your jquery

<asp:TextBox runat=server ID="txtTotalVersion" Visible="false" ClientIDMode="Static"></asp:TextBox>

<script>
    $(document).ready(function () {
        alert("#txtTotalVersion").val();
    })
</script>

reason is, the client id for your control might not be as it is assigned with ID="xxx", if the control is inside of another asp.net server control, after adding the ClientIDMode, you are telling your server to treat this control with a static ID

to learn more: msdn

Comments

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.