access dynamic textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marisenthil
    New Member
    • Jan 2009
    • 11

    access dynamic textbox

    How to access the value of the dynamic textbox by its id?
    I created more dynamic textbox using the below in loop
    Dim tb As New TextBox
    tb.ID = "txt_" + Str$(i)
    and it assigned unique id.
    then how to access each textbox value by its id without using javascript.
  • naga01
    New Member
    • Oct 2008
    • 3

    #2
    Try this
    Code:
    for(i=0; i<= 10; i++)
    {
    var textBox = document.getElementById( "txt_"  + i) 
    ...
    }

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Originally posted by marisenthil
      How to access the value of the dynamic textbox by its id?
      I created more dynamic textbox using the below in loop
      Dim tb As New TextBox
      tb.ID = "txt_" + Str$(i)
      and it assigned unique id.
      then how to access each textbox value by its id without using javascript.
      Try this
      Code:
      int i = 1;
              foreach (Control c in form1.Controls)
              {
                  if (c is Button)
                  {
                      if (c.ID == "Button"+i.ToString())
                      {
                          ((Button)(c)).Text = "Something";
                      }
                  }
              }

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Also, check out this article on How to use dynamic controls in asp.net.

        -Frinny

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          Instead of looping through you could also use FindControl...
          Code:
          Control c1 = null;
          
          c1=FindControl("Button1"); // Here you pass Id of control you are trying to find ..
                  if (c1 != null)
                  {
                      if (c1 is Button)
                      {
                          ((Button)(c1)).Text = "Something";
                      }
                  }

          Comment

          Working...