Beginner's problem: A problem with pre-filled forms

Discussion in 'ASP .Net' started by Toni, Jul 29, 2006.

  1. Toni

    Toni Guest

    Hello! I'm building an application where the user can update his own
    personal information in a database using a form. The program fetches the
    user's information from the database, fills the form with this information,
    then the user makes the changes that he wants, clicks the "Update" button
    and the updated information is sent back to the database. But I have a
    problem. My program is supposed to work like this:

    txtNamefield.text = "John Smith"
    - a text field is filled with old information fetched from the database
    - the user changes this name, and clicks "Update"

    Dim name as String
    name = txtNamefield.text
    Dim Sqlsentence as string
    Sqlsentence = "UPDATE tableUser SET NAME = '" & name & "' WHERE USERID=XXX;"
    - the value of the text field is read to the variable "name" and the
    Sqlsentence is executed.

    But the value sent to the database is still the same old value, "John
    Smith", even though the user changed it and it vas read to the variable
    "name".

    If I don't fill the textfields in advance the program reads the values
    correctly. I would be very happy if someone could let me know what I'm doing
    wrong. Thank you very much in advance!

    Toni S.
     
    Toni, Jul 29, 2006
    #1
    1. Advertising

  2. I think you are setting the text field every time the page loads
    INCLUDING when you post back the changed value.

    What you need to do is only set the text field when the page first
    loads but not when you click update and it posts back:

    If Not Page.IsPostBack Then
    'set values from database
    End If

    PS: Remember that the method you are using is dangerous security-wise
    as people could pass sql code through to your page. Using the
    validation controls will block this for you.



    Toni wrote:
    > Hello! I'm building an application where the user can update his own
    > personal information in a database using a form. The program fetches the
    > user's information from the database, fills the form with this information,
    > then the user makes the changes that he wants, clicks the "Update" button
    > and the updated information is sent back to the database. But I have a
    > problem. My program is supposed to work like this:
    >
    > txtNamefield.text = "John Smith"
    > - a text field is filled with old information fetched from the database
    > - the user changes this name, and clicks "Update"
    >
    > Dim name as String
    > name = txtNamefield.text
    > Dim Sqlsentence as string
    > Sqlsentence = "UPDATE tableUser SET NAME = '" & name & "' WHERE USERID=XXX;"
    > - the value of the text field is read to the variable "name" and the
    > Sqlsentence is executed.
    >
    > But the value sent to the database is still the same old value, "John
    > Smith", even though the user changed it and it vas read to the variable
    > "name".
    >
    > If I don't fill the textfields in advance the program reads the values
    > correctly. I would be very happy if someone could let me know what I'm doing
    > wrong. Thank you very much in advance!
    >
    > Toni S.
     
    cannontrodder, Jul 29, 2006
    #2
    1. Advertising

  3. Toni

    Mark Rae Guest

    "Toni" <> wrote in message
    news:uHfoF$...

    Could it simply be that you're fetching the initial values in the Page_Load
    event regardless of whether the page is being opened as a result of a
    postback or not...? E.g.

    If Not Page.IsPostback
    ' fetch the initial values - don't do this when updating!
    End If
     
    Mark Rae, Jul 29, 2006
    #3
  4. Page_Load() fires prior to button events.

    Make sure you are setting the value only when IsPostBack() is false. If not,
    you are setting the value again prior to saving, thus saving the original
    value.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************************************************
    Think Outside the Box!
    *************************************************
    "Toni" <> wrote in message
    news:uHfoF$...
    > Hello! I'm building an application where the user can update his own
    > personal information in a database using a form. The program fetches the
    > user's information from the database, fills the form with this
    > information, then the user makes the changes that he wants, clicks the
    > "Update" button and the updated information is sent back to the database.
    > But I have a problem. My program is supposed to work like this:
    >
    > txtNamefield.text = "John Smith"
    > - a text field is filled with old information fetched from the database
    > - the user changes this name, and clicks "Update"
    >
    > Dim name as String
    > name = txtNamefield.text
    > Dim Sqlsentence as string
    > Sqlsentence = "UPDATE tableUser SET NAME = '" & name & "' WHERE
    > USERID=XXX;"
    > - the value of the text field is read to the variable "name" and the
    > Sqlsentence is executed.
    >
    > But the value sent to the database is still the same old value, "John
    > Smith", even though the user changed it and it vas read to the variable
    > "name".
    >
    > If I don't fill the textfields in advance the program reads the values
    > correctly. I would be very happy if someone could let me know what I'm
    > doing wrong. Thank you very much in advance!
    >
    > Toni S.
    >
     
    msnews.microsoft.com, Jul 29, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rocky Moore
    Replies:
    7
    Views:
    1,751
    mikeb
    Jan 14, 2004
  2. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,065
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  3. Wladimir Borsov
    Replies:
    7
    Views:
    479
    Raymond Loman
    May 5, 2004
  4. Juha Nieminen
    Replies:
    3
    Views:
    1,157
    Juha Nieminen
    Feb 22, 2008
  5. Replies:
    0
    Views:
    141
Loading...

Share This Page