I do it this way:
private static TextBox[] orderCTNTextBox;
private void buildTable()
{
while (blahblah)
{
orderCTNTextBox[i] = new TextBox(); //i is a counter
orderCTNTextBox[i].Text = "blah blah";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
for(blahblah)
{
somevar = orderCTNTextBox[i].Text; //and here it goes
wrong...
}
}
TheSteph schreef:
> Don't you forget to Add the TextBoxes you create in the Array ?
>
> TextBox Mt1 = new TextBox();
> TextBox Mt2 = new TextBox();
> //Create Array and Add the TextBox's
> TextBox[] MyArray = new TextBox[] { Mt1, Mt2 };
>
>
> "jan82" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> >
> > Michael C schreef:
> >
> > > "jan82" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Hi everybody
> > > >
> > > > I declared a private static array of textboxes at the top of a class,
> > > >
> > > > then i generate the array elements (new textbox()) in a separate
> > > > function (private void in the same class),
> > > >
> > > > then i try to call these elements from another function in the same
> > > > class (protected void)
> > > >
> > > > and that causes a nullreference exception. Can anybody tell me what
> > > > i'm doing wrong?
> > >
> > > Either the function hasn't been called or something set the array back
> to
> > > null.
> > >
> > > Or maybe you are expecting the new TextBox[] to create textboxes? All it
> > > does it create an array of nulls, you need to create each textbox
> > > individually.
> >
> > I create each textbox individually, and I show them on the screen, so
> > they are created. Then when trying to get the "text" property of these
> > textboxes from another function (in the same class), I get the error.
> >
|