get content of text boxes dynamically created

Discussion in 'ASP .Net' started by tarscher@gmail.com, Aug 31, 2006.

  1. Guest

    Hi all,

    I create a set of text-boxes based on user input:

    for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    i++)
    {
    myTextBox = new TextBox();
    myTextBox.Columns = 5;
    myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    myTextBox.TabIndex = (short) (i+1);
    buttonPlaceHolder.Controls.Add(myTextBox);
    }

    The text boxes are followed by a button that, when clicked, should get
    the content form the text boxes and put em in a database. How can I get
    the content from teh text boxes?

    I cannot use
    someVar = parameterTextBox0.text
    since it is not known

    Thanks in advance
    Stijn
     
    , Aug 31, 2006
    #1
    1. Advertising

  2. Teemu Keiski Guest

    But you can use Page.FindControl

    TextBox tb = (TextBox)Page.FindControl("parameterTextBox0");


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    <> wrote in message
    news:...
    > Hi all,
    >
    > I create a set of text-boxes based on user input:
    >
    > for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    > i++)
    > {
    > myTextBox = new TextBox();
    > myTextBox.Columns = 5;
    > myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    > myTextBox.TabIndex = (short) (i+1);
    > buttonPlaceHolder.Controls.Add(myTextBox);
    > }
    >
    > The text boxes are followed by a button that, when clicked, should get
    > the content form the text boxes and put em in a database. How can I get
    > the content from teh text boxes?
    >
    > I cannot use
    > someVar = parameterTextBox0.text
    > since it is not known
    >
    > Thanks in advance
    > Stijn
    >
     
    Teemu Keiski, Aug 31, 2006
    #2
    1. Advertising

  3. Stijn,

    buttonPlaceHolder.FindControl ("parameterTextBox1") as TextBox

    should do.


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    <> wrote in message
    news:...
    > Hi all,
    >
    > I create a set of text-boxes based on user input:
    >
    > for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    > i++)
    > {
    > myTextBox = new TextBox();
    > myTextBox.Columns = 5;
    > myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    > myTextBox.TabIndex = (short) (i+1);
    > buttonPlaceHolder.Controls.Add(myTextBox);
    > }
    >
    > The text boxes are followed by a button that, when clicked, should get
    > the content form the text boxes and put em in a database. How can I get
    > the content from teh text boxes?
    >
    > I cannot use
    > someVar = parameterTextBox0.text
    > since it is not known
    >
    > Thanks in advance
    > Stijn
    >
     
    Eliyahu Goldin, Aug 31, 2006
    #3
  4. Guest

    Thanks for the reply. i haven't made it work yet though. It seems that
    FindControl can't find the textbox since null is returned. The
    textboxes are placed inside a view (and multiview) and then inside a
    placeholder (suing a masterpage). Maybe this is the reason why null is
    returned?

    Regards,
    Stijn

    Teemu Keiski schreef:

    > But you can use Page.FindControl
    >
    > TextBox tb = (TextBox)Page.FindControl("parameterTextBox0");
    >
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > <> wrote in message
    > news:...
    > > Hi all,
    > >
    > > I create a set of text-boxes based on user input:
    > >
    > > for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    > > i++)
    > > {
    > > myTextBox = new TextBox();
    > > myTextBox.Columns = 5;
    > > myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    > > myTextBox.TabIndex = (short) (i+1);
    > > buttonPlaceHolder.Controls.Add(myTextBox);
    > > }
    > >
    > > The text boxes are followed by a button that, when clicked, should get
    > > the content form the text boxes and put em in a database. How can I get
    > > the content from teh text boxes?
    > >
    > > I cannot use
    > > someVar = parameterTextBox0.text
    > > since it is not known
    > >
    > > Thanks in advance
    > > Stijn
    > >
     
    , Sep 1, 2006
    #4
  5. Guest

    Hi all,

    I tried the findcontrol with textbox I added via the editor but that
    also returned a null. I used Page.findcontrol(id) and just
    findcontrol(id).

    Someone has an idea what I'm doing wrong?

    Regards
    Stijn


    schreef:

    > Thanks for the reply. i haven't made it work yet though. It seems that
    > FindControl can't find the textbox since null is returned. The
    > textboxes are placed inside a view (and multiview) and then inside a
    > placeholder (suing a masterpage). Maybe this is the reason why null is
    > returned?
    >
    > Regards,
    > Stijn
    >
    > Teemu Keiski schreef:
    >
    > > But you can use Page.FindControl
    > >
    > > TextBox tb = (TextBox)Page.FindControl("parameterTextBox0");
    > >
    > >
    > > --
    > > Teemu Keiski
    > > ASP.NET MVP, AspInsider
    > > Finland, EU
    > > http://blogs.aspadvice.com/joteke
    > >
    > > <> wrote in message
    > > news:...
    > > > Hi all,
    > > >
    > > > I create a set of text-boxes based on user input:
    > > >
    > > > for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    > > > i++)
    > > > {
    > > > myTextBox = new TextBox();
    > > > myTextBox.Columns = 5;
    > > > myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    > > > myTextBox.TabIndex = (short) (i+1);
    > > > buttonPlaceHolder.Controls.Add(myTextBox);
    > > > }
    > > >
    > > > The text boxes are followed by a button that, when clicked, should get
    > > > the content form the text boxes and put em in a database. How can I get
    > > > the content from teh text boxes?
    > > >
    > > > I cannot use
    > > > someVar = parameterTextBox0.text
    > > > since it is not known
    > > >
    > > > Thanks in advance
    > > > Stijn
    > > >
     
    , Sep 1, 2006
    #5
  6. You need to call FindControl on the control that directly contains the
    control you are trying to find. Did you try my suggestion

    buttonPlaceHolder.FindControl ("parameterTextBox1") as TextBox ?

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    <> wrote in message
    news:...
    > Hi all,
    >
    > I tried the findcontrol with textbox I added via the editor but that
    > also returned a null. I used Page.findcontrol(id) and just
    > findcontrol(id).
    >
    > Someone has an idea what I'm doing wrong?
    >
    > Regards
    > Stijn
    >
    >
    > schreef:
    >
    >> Thanks for the reply. i haven't made it work yet though. It seems that
    >> FindControl can't find the textbox since null is returned. The
    >> textboxes are placed inside a view (and multiview) and then inside a
    >> placeholder (suing a masterpage). Maybe this is the reason why null is
    >> returned?
    >>
    >> Regards,
    >> Stijn
    >>
    >> Teemu Keiski schreef:
    >>
    >> > But you can use Page.FindControl
    >> >
    >> > TextBox tb = (TextBox)Page.FindControl("parameterTextBox0");
    >> >
    >> >
    >> > --
    >> > Teemu Keiski
    >> > ASP.NET MVP, AspInsider
    >> > Finland, EU
    >> > http://blogs.aspadvice.com/joteke
    >> >
    >> > <> wrote in message
    >> > news:...
    >> > > Hi all,
    >> > >
    >> > > I create a set of text-boxes based on user input:
    >> > >
    >> > > for (int i = 0; i < Convert.ToInt16(keywordsDropDownList.Text);
    >> > > i++)
    >> > > {
    >> > > myTextBox = new TextBox();
    >> > > myTextBox.Columns = 5;
    >> > > myTextBox.ID = "parameterTextBox"+Convert.ToInt16(i);
    >> > > myTextBox.TabIndex = (short) (i+1);
    >> > > buttonPlaceHolder.Controls.Add(myTextBox);
    >> > > }
    >> > >
    >> > > The text boxes are followed by a button that, when clicked, should
    >> > > get
    >> > > the content form the text boxes and put em in a database. How can I
    >> > > get
    >> > > the content from teh text boxes?
    >> > >
    >> > > I cannot use
    >> > > someVar = parameterTextBox0.text
    >> > > since it is not known
    >> > >
    >> > > Thanks in advance
    >> > > Stijn
    >> > >

    >
     
    Eliyahu Goldin, Sep 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. muthu
    Replies:
    2
    Views:
    822
    bruce barker \(sqlwork.com\)
    Apr 26, 2006
  2. msimmons
    Replies:
    0
    Views:
    550
    msimmons
    Jul 16, 2009
  3. Keefe Goldfisher via .NET 247

    Sizing text entry boxes on in-place editing of datagrid row with dynamically created columns

    Keefe Goldfisher via .NET 247, Mar 7, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    195
    Keefe Goldfisher via .NET 247
    Mar 7, 2005
  4. Ahmet Gunes
    Replies:
    0
    Views:
    196
    Ahmet Gunes
    Nov 7, 2003
  5. vega80
    Replies:
    1
    Views:
    203
Loading...

Share This Page