Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Beginner's problem: A problem with pre-filled forms

Reply
Thread Tools

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

 
 
Toni
Guest
Posts: n/a
 
      07-29-2006
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.


 
Reply With Quote
 
 
 
 
cannontrodder
Guest
Posts: n/a
 
      07-29-2006
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.


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      07-29-2006
"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


 
Reply With Quote
 
msnews.microsoft.com
Guest
Posts: n/a
 
      07-29-2006
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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forms authentication -- expired forms cookie vs. not provided forms cookie Eric ASP .Net Security 2 01-27-2006 10:09 PM
embedded windows forms into web forms for control =?Utf-8?B?ZGF2aWQ=?= ASP .Net 2 04-10-2005 01:07 PM
Creating ASP.NET forms, that act like HTML forms jlopes151 ASP .Net 2 03-14-2005 01:01 AM
Forms Authentication question: How to have some pages open and some requiring forms authentication Eric ASP .Net 2 02-13-2004 02:14 PM
Web Forms VS Windows Forms Brendan Miller ASP .Net 2 08-11-2003 09:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57