getting values from a textbox

getting values from a textbox

am 14.01.2008 22:16:15 von Patrice

Using codebehind, I populate some textboxes in the Page_Load method.
At this point the user can edit the data in the textboxes.
Then I want to click on a Save button and write the edited data in the
textboxes into a table. But referencing the textboxes only shows the
original value, not the newly edited values.

protected void btnSave_Click(object sender, EventArgs e)
{
// This contains original values not edited values
dsContact.Tables["Contact"].Rows[0]["FName"] = txtFirstName.Text;
dsContact.Tables["Contact"].Rows[0]["LName"] = txtLastName.Text;
....
}


Thanks.

Re: getting values from a textbox

am 14.01.2008 22:21:34 von sloan

Make sure the txt boxes are "runat='server'" variety.

Aka, not an Html Textbox (input), but rather a




"J" wrote in message
news:13onk81tm2sopb6@corp.supernews.com...
> Using codebehind, I populate some textboxes in the Page_Load method.
> At this point the user can edit the data in the textboxes.
> Then I want to click on a Save button and write the edited data in the
> textboxes into a table. But referencing the textboxes only shows the
> original value, not the newly edited values.
>
> protected void btnSave_Click(object sender, EventArgs e)
> {
> // This contains original values not edited values
> dsContact.Tables["Contact"].Rows[0]["FName"] = txtFirstName.Text;
> dsContact.Tables["Contact"].Rows[0]["LName"] = txtLastName.Text;
> ...
> }
>
>
> Thanks.
>
>

Re: getting values from a textbox

am 14.01.2008 22:47:00 von Patrice

They are of the asp variety.

"sloan" wrote in message
news:utPEDNvVIHA.4712@TK2MSFTNGP04.phx.gbl...
> Make sure the txt boxes are "runat='server'" variety.
>
> Aka, not an Html Textbox (input), but rather a
>
>
>
>
> "J" wrote in message
> news:13onk81tm2sopb6@corp.supernews.com...
>> Using codebehind, I populate some textboxes in the Page_Load method.
>> At this point the user can edit the data in the textboxes.
>> Then I want to click on a Save button and write the edited data in the
>> textboxes into a table. But referencing the textboxes only shows the
>> original value, not the newly edited values.
>>
>> protected void btnSave_Click(object sender, EventArgs e)
>> {
>> // This contains original values not edited values
>> dsContact.Tables["Contact"].Rows[0]["FName"] = txtFirstName.Text;
>> dsContact.Tables["Contact"].Rows[0]["LName"] = txtLastName.Text;
>> ...
>> }
>>
>>
>> Thanks.
>>
>>
>
>

Re: getting values from a textbox

am 14.01.2008 23:01:50 von sloan

Something weird.

On a button save click event (which is a postback essentially) ..code like
this should work


string newFirstName = txtFirstName.Text;


Try that first, and get the "did the ds update" out of the debugging
equation.

You might want to consider a strongly typed dataset as well.
All that row(indexer).column(indexer) stuff is a recipe for bugs and really
for the birds.
ADO.Net is not an upgrade to ADO,....



See example below.

...............................


Add / New Item / DataSet.

Call it "EmployeeDS". (or EmployeeDS.xsd)

Right click (in the design area) ... Add a table. "Employee"

Add 3 columns

ID (int)
LastName (string)
FirstName (string)


...
then you can "code up" a version like this

EmployeeDS ds = new EmployeeDS();

//first way
ds.Employee.AddNewEmployeeRow ( 123, "Smith" , "John");
//second way
EmployeeDS.Employee.EmployeeRow newRow = ds.Employee.NewEmployeeRow();
newRow.ID = 234;
newRow.LastName = "Jones";
newRow.FirstName = "Mary";

ds.Employee.AddNewEmployeeRow ( newRow ) ;

string x = ds.GetXml();




"J" wrote in message
news:13onm1mrn8sf4ec@corp.supernews.com...
> They are of the asp variety.
>
> "sloan" wrote in message
> news:utPEDNvVIHA.4712@TK2MSFTNGP04.phx.gbl...
>> Make sure the txt boxes are "runat='server'" variety.
>>
>> Aka, not an Html Textbox (input), but rather a
>>
>>
>>
>>
>> "J" wrote in message
>> news:13onk81tm2sopb6@corp.supernews.com...
>>> Using codebehind, I populate some textboxes in the Page_Load method.
>>> At this point the user can edit the data in the textboxes.
>>> Then I want to click on a Save button and write the edited data in the
>>> textboxes into a table. But referencing the textboxes only shows the
>>> original value, not the newly edited values.
>>>
>>> protected void btnSave_Click(object sender, EventArgs e)
>>> {
>>> // This contains original values not edited values
>>> dsContact.Tables["Contact"].Rows[0]["FName"] = txtFirstName.Text;
>>> dsContact.Tables["Contact"].Rows[0]["LName"] = txtLastName.Text;
>>> ...
>>> }
>>>
>>>
>>> Thanks.
>>>
>>>
>>
>>
>
>

Re: getting values from a textbox

am 15.01.2008 00:19:14 von Scott Roberts

You realize that when the user clicks the Save button that another postback
occurs and the Page_Load event happens again, right? If you are setting the
value of the Textbox in Page_Load without checking the IsPostBack property
then you are overwriting the user's changes.

You need to get a firm grasp on the ASP.NET page lifecycle:
http://www.codeproject.com/KB/aspnet/lifecycle.aspx



"J" wrote in message
news:13onk81tm2sopb6@corp.supernews.com...
> Using codebehind, I populate some textboxes in the Page_Load method.
> At this point the user can edit the data in the textboxes.
> Then I want to click on a Save button and write the edited data in the
> textboxes into a table. But referencing the textboxes only shows the
> original value, not the newly edited values.
>
> protected void btnSave_Click(object sender, EventArgs e)
> {
> // This contains original values not edited values
> dsContact.Tables["Contact"].Rows[0]["FName"] = txtFirstName.Text;
> dsContact.Tables["Contact"].Rows[0]["LName"] = txtLastName.Text;
> ...
> }
>
>
> Thanks.
>
>