Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Problem At Accessing Dynamic Controls in ASP.NET

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2007-08-20 : 03:23:51
Hi,

here in my web page page1.aspx i have created a table control by:

<asp:Table ID = "Table1" GridLines = "both" HorizontalAlign = "center" Font-Size = "Medium" CellPadding = "5" CellSpacing = "0" runat = "server" style="z-index: 105; left: 64px; position: absolute; top: 212px">
</asp:Table>

in my page i have two text boxes txtRow and txtColumn to take the input to genretable table.

in Generate button i have wrriten like this:
protected void btnGenerate_Click(object sender, EventArgs e)
{
int _rowCount = int.Parse(txtRow.Text.ToString());
int _colCount = int.Parse(txtColumn.Text.ToString());
for (int i = 0; i < _rowCount; i++)
{
TableRow _tr = new TableRow();
Table1.Rows.Add(_tr);
for (int j = 0; j < _colCount; j++)
{
TableCell _tc = new TableCell();
System.Web.UI.WebControls.TextBox _txtBox = new TextBox();
_txtBox.ID = "_txtBox1";


_tc.Controls.Add(_txtBox);
_tr.Cells.Add(_tc);
}
}

}

after this i have taken label to display the text typed on dynamically created text box.

so, i have taken one more button btnCkeck.

in that button click, i had written the following code:

protected void btnCheck_Click(object sender, EventArgs e)
{
string _text = "_txtBox1";
Table _tab = (Table)this.Page.FindControl("Table1");
if (_tab != null)
{


TextBox _txt = (TextBox)_tab.FindControl(_text);
if (_txt != null)
{
Label3.Text = _txt.Text.ToString();
}

}
}

but the TextBox is not accessing. the Table "_tab" is accessing but the text box in it is not accessing. the if block is not getting executed. please show me a way to access it.

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

salmonraju
Yak Posting Veteran

54 Posts

Posted - 2007-08-20 : 08:19:11
hi Ramu,
when you are Clicking BtnCheck you loose all the data in the table(State Management), i.e,
_tab is null,I tried to store the tab in viewstate but i am getting error message
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2007-08-20 : 11:04:00
yeah salmon,
I Got It Through Maintaining My Table In Session

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page
   

- Advertisement -