Text returned from a textbox.

G

Gary Monk

I have a strange problem, I think. I have a web page with
a text box. In the page load function I set the Text
property to a value (the value is received from a SQL
query).

The user is able to change the value in the textbox on
the web page. When the user clicks on the save button I
update the database with the new value, except that when
I update the database the value is the same as what was
initialy in the textbox. The Text property never changes
even when I modify the value on the web page.

I'm using C#. Has anyone seen this problem before?

Thanks for the help!!

Gary
 
G

Gary Monk

Jeff,

Thanks for the reply.

Not sure what you mean by the update command code. I read
the database and update the textbox through the Text
property..

AdminCompanyName.Text = companyName;

The Save button click method then executes the sql update
statement that uses the Text property to update the
database...

SQL = SQL + "CompanyName = '" + AdminCompanyName.Text
+ "'";

Shouldn't the Text property reflect what was typed into
the textbox?

Thanks,
Gary
 
L

Lewis Wang [MSFT]

Jeff, Thanks for the reply.

Hi Gary,

This is because when we post back a page, the Page_Load event is processed
before the Button_Click event. So,the textbox's value is initialized again
in Page_Load before we get it's value in Button_Click.

To resolve this problem, we just need to initialize the TextBox in
"if(!this.IsPostBack){...}" in the Page_Load. Then when we click a button,
the TextBox'value will not be initialized again.

Check this link for more information:
Page.IsPostBack Property
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfSystemWebUIPageClassIsPostBackTopic.asp>

I would also like to recommend one good article to you:
The ASP.NET Page Life Cycle
http://www.15seconds.com/issue/020102.htm

Hope this helps.

Best Regards,
Lewis

--------------------
| Content-Class: urn:content-classes:message
| From: "Gary Monk" <[email protected]>
| Sender: "Gary Monk" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Text returned from a textbox.
| Date: Wed, 30 Jul 2003 08:24:17 -0700
| Lines: 51
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNWrqPk1GSOsNYhSrKFuFsHojAdqQ==
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:13540
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Jeff,
|
| Thanks for the reply.
|
| Not sure what you mean by the update command code. I read
| the database and update the textbox through the Text
| property..
|
| AdminCompanyName.Text = companyName;
|
| The Save button click method then executes the sql update
| statement that uses the Text property to update the
| database...
|
| SQL = SQL + "CompanyName = '" + AdminCompanyName.Text
| + "'";
|
| Shouldn't the Text property reflect what was typed into
| the textbox?
|
| Thanks,
| Gary
| >-----Original Message-----
| >can u post the update command code ?
| >
| >| >> I have a strange problem, I think. I have a web page
| with
| >> a text box. In the page load function I set the Text
| >> property to a value (the value is received from a SQL
| >> query).
| >>
| >> The user is able to change the value in the textbox on
| >> the web page. When the user clicks on the save button I
| >> update the database with the new value, except that
| when
| >> I update the database the value is the same as what was
| >> initialy in the textbox. The Text property never
| changes
| >> even when I modify the value on the web page.
| >>
| >> I'm using C#. Has anyone seen this problem before?
| >>
| >> Thanks for the help!!
| >>
| >> Gary
| >
| >
| >.
| >
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top