Groups | Blog | Home
all groups > asp.net webcontrols > july 2003 >

asp.net webcontrols : Text returned from a textbox.


Gary Monk
7/29/2003 7:24:15 PM
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!!

jeff
7/29/2003 11:10:46 PM
can u post the update command code ?

[quoted text, click to view]

Gary Monk
7/30/2003 8:24:17 AM
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
[quoted text, click to view]
v-lwang NO[at]SPAM online.microsoft.com
7/31/2003 6:01:56 AM
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" <g_monk@hotmail.com>
| Sender: "Gary Monk" <g_monk@hotmail.com>
| References: <45bb01c35641$ac3fc830$a001280a@phx.gbl>
<uQ4UKhkVDHA.2344@TK2MSFTNGP10.phx.gbl>
| Subject: Re: Text returned from a textbox.
| Date: Wed, 30 Jul 2003 08:24:17 -0700
| Lines: 51
| Message-ID: <016801c356ae$a3e6b550$a101280a@phx.gbl>
| 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 ?
| >
[quoted text, click to view]
| >> 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
| >
| >
| >.
| >
|
AddThis Social Bookmark Button