ASP.NET rookie needs help finding postback data

G

Guest

I'm new to ASP.NET and fairly inexperienced with web development in general,
but I've been a professional software dev for over 10 years, C++, Unix and
windows, C# the past 4 years.

I've been working on a personal ASP.NET project, basically as a learning
tool and I have a major issue which is really really getting on my nerves.

I'm creating a web application in ASP.NET 2.0 which dynamically populates a
table with text and text boxes. This table has two columns; in the left colum
are fields labelling the text boxes on the right column.

After post back, I cannot for the life of me find the values that were
entered into the text boxes. When I turn tracing on, I see in the 'Form
Collection' that my values have in fact been kept via ViewState, but when I
go into the Table object, the 'rows' are empty.

I'm sure this is going to be a difficult one to diagnose via this post as it
appears to be pretty vague, bug perhaps if you can explain to me how to find
a control by either the control ID or by the Unique ID? The Unique ID is
shown in the trace output. I've tried using a debugger and examined the
Table object in a watch window, but there are a million nodes on that.

Please help!! This has been keeping me up at night. It seems like such a
simple friggin thing.
 
K

Ken Cox [Microsoft MVP]

Hi Jann,

What kind of table are you using? A plain HTML table? A datagrid? An ASP.NET
table?

It would help to see the code that isn't working.

Ken
Microsoft MVP [ASP.NET]
 
G

Guest

I'll post the source code tonight, or email it, as I currently don't have
access to it.

However, I am using a master page, and on that master page I have a content
placeholder, and in the implementation page that uses that master page, I
have in that placeholder:
<asp:Table runat="server" ID="QuestionTable" />

Then in my code behind page I populate that table with rows, each row
consisting of two cells. The first cell just has some text, the next cell has
a textbox.
This is done at runtime because the user can make choices which will
determine how many rows are put into that table.

In the Page_Init/ or Page_load or whatever it was (I don't remember the
function name exactly, but its the one method that VS puts in there for you)
The first time the page loads, I populate the table, and I can access the
first row->second cell with this:
((TextBox)this.QuestionTable.Rows[0].Cells[1].Controls[0]).Text; I can set
the text and I can read it. But when I put the same thing after checking for
IsPostBack, it doesn't have the posted back values!!!
I've looked at all kinds of data in the debugger, I've looked at the trace
output, I just cant find this data!

Thanks for getting back to me so soon.

Jaan

--
Jaan


Ken Cox said:
Hi Jann,

What kind of table are you using? A plain HTML table? A datagrid? An ASP.NET
table?

It would help to see the code that isn't working.

Ken
Microsoft MVP [ASP.NET]

jrett said:
I'm new to ASP.NET and fairly inexperienced with web development in
general,
but I've been a professional software dev for over 10 years, C++, Unix and
windows, C# the past 4 years.

I've been working on a personal ASP.NET project, basically as a learning
tool and I have a major issue which is really really getting on my nerves.

I'm creating a web application in ASP.NET 2.0 which dynamically populates
a
table with text and text boxes. This table has two columns; in the left
colum
are fields labelling the text boxes on the right column.

After post back, I cannot for the life of me find the values that were
entered into the text boxes. When I turn tracing on, I see in the 'Form
Collection' that my values have in fact been kept via ViewState, but when
I
go into the Table object, the 'rows' are empty.

I'm sure this is going to be a difficult one to diagnose via this post as
it
appears to be pretty vague, bug perhaps if you can explain to me how to
find
a control by either the control ID or by the Unique ID? The Unique ID is
shown in the trace output. I've tried using a debugger and examined the
Table object in a watch window, but there are a million nodes on that.

Please help!! This has been keeping me up at night. It seems like such a
simple friggin thing.
 
G

Guest

Okay, apparently there is not way to post my sources, so I'll try to copy and
paste the relevant portions.


protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
// if we don't re-render the table and it's text boxes, the
viewstate for these controls is lost.
TableRow[] tableRows =
WebMadLibEngine.GetMadLibTableData((string)this.ViewState["FilePathName"]);
this.QuestionTable.Rows.AddRange(tableRows);

//Server.Transfer("MadLibDisplayPage.aspx");

Response.Write(string.Format("The first text box says: [{0}]",

((TextBox)this.QuestionTable.Rows[0].Cells[1].Controls[0]).Text));

((TextBox)this.QuestionTable.Rows[2].Cells[1].Controls[0]).Text
= "Setting this also the hard way.";
}
else if (this.PreviousPage != null)
{
this.MadLibTitle.Text =
Path.GetFileNameWithoutExtension(PreviousPage.SelectedMadLibFilePathName);
this.ViewState.Add("FilePathName",
PreviousPage.SelectedMadLibFilePathName);

TableRow[] tableRows =
WebMadLibEngine.GetMadLibTableData(PreviousPage.SelectedMadLibFilePathName);

this.QuestionTable.Rows.AddRange(tableRows);

((TextBox)this.QuestionTable.Rows[1].Cells[1].Controls[0]).Text
= "Setting this the hard way.";
}
else
{
// if there is no previous page, then let's load it!!
Server.Transfer("MadLibSelectionPage.aspx");
}
}




--
Jaan


jrett said:
I'll post the source code tonight, or email it, as I currently don't have
access to it.

However, I am using a master page, and on that master page I have a content
placeholder, and in the implementation page that uses that master page, I
have in that placeholder:
<asp:Table runat="server" ID="QuestionTable" />

Then in my code behind page I populate that table with rows, each row
consisting of two cells. The first cell just has some text, the next cell has
a textbox.
This is done at runtime because the user can make choices which will
determine how many rows are put into that table.

In the Page_Init/ or Page_load or whatever it was (I don't remember the
function name exactly, but its the one method that VS puts in there for you)
The first time the page loads, I populate the table, and I can access the
first row->second cell with this:
((TextBox)this.QuestionTable.Rows[0].Cells[1].Controls[0]).Text; I can set
the text and I can read it. But when I put the same thing after checking for
IsPostBack, it doesn't have the posted back values!!!
I've looked at all kinds of data in the debugger, I've looked at the trace
output, I just cant find this data!

Thanks for getting back to me so soon.

Jaan

--
Jaan


Ken Cox said:
Hi Jann,

What kind of table are you using? A plain HTML table? A datagrid? An ASP.NET
table?

It would help to see the code that isn't working.

Ken
Microsoft MVP [ASP.NET]

jrett said:
I'm new to ASP.NET and fairly inexperienced with web development in
general,
but I've been a professional software dev for over 10 years, C++, Unix and
windows, C# the past 4 years.

I've been working on a personal ASP.NET project, basically as a learning
tool and I have a major issue which is really really getting on my nerves.

I'm creating a web application in ASP.NET 2.0 which dynamically populates
a
table with text and text boxes. This table has two columns; in the left
colum
are fields labelling the text boxes on the right column.

After post back, I cannot for the life of me find the values that were
entered into the text boxes. When I turn tracing on, I see in the 'Form
Collection' that my values have in fact been kept via ViewState, but when
I
go into the Table object, the 'rows' are empty.

I'm sure this is going to be a difficult one to diagnose via this post as
it
appears to be pretty vague, bug perhaps if you can explain to me how to
find
a control by either the control ID or by the Unique ID? The Unique ID is
shown in the trace output. I've tried using a debugger and examined the
Table object in a watch window, but there are a million nodes on that.

Please help!! This has been keeping me up at night. It seems like such a
simple friggin thing.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top