Very frustrating: can't put user's textbox input back into database.

  • Thread starter Thread starter Mike Lerch
  • Start date Start date
M

Mike Lerch

Wow, I hope someone has a moment to help, because I'm losing my mind.

I want to present the user with a page of information, let them edit
it, and post the changes back to the database. I've got some
textboxes as part of the main form and a repeater control, each bound
to a different table in the dataset (the main form to the parent, the
repeater to the child records, sort of an Order / Details thing)

Everything involving GETTING the data is working fine: based on the
querystring, two data adapters fill one dataset with the info. The
textboxes that are just sitting there on the form are like this:

<asp:textbox id=tbCustomerFirstName runat="server"
Text='<%# DataBinder.Eval(dsParentData,
"Tables[Order].DefaultView.[0].CustomerFirstName") %>'>
</asp:textbox>

And again, they fill with data fine with these two lines in void
Page_Load:

daOrders.SelectCommand.Parameters["@OrderNumber"].Value =
Request.QueryString["OrderNumber"];
daOrders.Fill(dsParentData, "Order");
Page.DataBind();

The problem is when I try evaluate what has changed in the textbox to
post it back to the database.

I've tried a couple ways. I've attached a TextChanged event and
stepped through the code. When I evaluate this.tbCustomerFirstName,
it shows up as an empty string even if I've typed stuff into the
textbox!!! How could this be?

I've also tried just forcing the issue with a button that has code
like this:

DataTable dtCurrent;
dtCurrent = dsParentData.Tables["Order"];
DataRow drCurrent = dtCurrent.Rows[0];
drCurrent.BeginEdit();
drCurrent["CustomerFirstName"] = this.tbCustomerFirstName.Text;
//No reason to go lower than here, because
//this.tbCustomerFirstName.Text evaluates
//to "" even if I've typed something in.
drCurrent.EndEdit();
daOrders.Update(dsParentData, "Order")


Hope this isn't too long or too narrative but would really appreciate
the answer: why is the Text property coming up blank even when stuff
is typed in?

Lerch
 
Hi

If the textBoxes are part of the repeater control, you will need to use FindControl to access them in Postback.

It's not in the repeater: it's just sitting in the main form outsite
the repeater. It's literally like:

<form>
<asp:textbox id=tbCustomerFirstName runat="server"
Text='<%# DataBinder.Eval(dsParentData,
"Tables[Order].DefaultView.[0].CustomerFirstName") %>'>
</asp:textbox>
<asp:Repeater .....></asp:Repeater>
</form>

That's why this is driving me crazy!
If EnableViewState is true for the page, then you should not rebind in the pageLoad postback.
If EnableViewState is false for the page, then you must always rebind in pageLoad.

I have the viewstate turned off for the controls because I want it to
bind on every load whether it's a postback or not. But I think that
EnableViewState *is* turned on for the page...guess I don't need that!

Lerch
 
Back
Top