getting values from a textbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J

    getting values from a textbox

    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(o bject sender, EventArgs e)
    {
    // This contains original values not edited values
    dsContact.Table s["Contact"].Rows[0]["FName"] = txtFirstName.Te xt;
    dsContact.Table s["Contact"].Rows[0]["LName"] = txtLastName.Tex t;
    ....
    }


    Thanks.


  • sloan

    #2
    Re: getting values from a textbox

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

    Aka, not an Html Textbox (input), but rather a
    <asp:textbox> </asp:textbox>



    "J" <nobody@nowhere .comwrote in message
    news:13onk81tm2 sopb6@corp.supe rnews.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(o bject sender, EventArgs e)
    {
    // This contains original values not edited values
    dsContact.Table s["Contact"].Rows[0]["FName"] = txtFirstName.Te xt;
    dsContact.Table s["Contact"].Rows[0]["LName"] = txtLastName.Tex t;
    ...
    }
    >
    >
    Thanks.
    >
    >

    Comment

    • Scott Roberts

      #3
      Re: getting values from a textbox

      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:




      "J" <nobody@nowhere .comwrote in message
      news:13onk81tm2 sopb6@corp.supe rnews.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(o bject sender, EventArgs e)
      {
      // This contains original values not edited values
      dsContact.Table s["Contact"].Rows[0]["FName"] = txtFirstName.Te xt;
      dsContact.Table s["Contact"].Rows[0]["LName"] = txtLastName.Tex t;
      ...
      }
      >
      >
      Thanks.
      >
      >

      Comment

      Working...