ASP:TextBox

A

Alex

I am a newbie to ASP.NET...

What I was trying to do... but yet to succeed in...

I am building a customer info database... and on default,
I want to display the customer's basic information in the
TextBox on Page_Load... but, also allow user to update the
information

For example: Street1 of the home address
ASP:TextBox id=dbStreet1 value=<%=litDbStreet1%>

but also allow update all within the same form on the same
text box to do the following...
ASP:TextBox id=dbStreet1 runat=server

I tried everything I know... but not works...

Please advise
thanks
Alex
 
G

George Zacharias

Try the attribute "text" instead of "value".

The best way to do this is declare an ASP textbox in the code-behind page
and assign the value of the variable to dbStreet1.Text from the Page_Load
event.

George Zacharias.
 
A

Alex

Hi,

This is what I did...

Page_Load()
dbStreet1.Text = "whatever st"

Update_Text()
SQL update cmd ==> "update ..... dbstreet1='" &
dbStreet1.Text "' where <match critera>=<match this>"

Inside the HTML Main Body
<form method=post>
<ASP:TextBox id=dbStreet1 value=dbStreet1.Text
runat=server/>
</form>

It works on initial load.. where it takes the info from
DB... but the update doesn't seem to regonize the new value

Any clue?
thanks
Alex
 
A

Alex

Hi,

This is what I did...

Page_Load()
dbStreet1.Text = "whatever st"

Update_Text()
SQL update cmd ==> "update ..... dbstreet1='" &
dbStreet1.Text "' where <match critera>=<match this>"

Inside the HTML Main Body
<form method=post>
<ASP:TextBox id=dbStreet1 value=dbStreet1.Text
runat=server/>
</form>

It works on initial load.. where it takes the info from
DB... but the update doesn't seem to regonize the new value

Any clue?
thanks
Alex
 
D

David Waz...

Alex,

You have to read some fundamental books on ASPX programming - that's #1.
There are bunches and bunches of inexpensive, quick, easy books on the
subject.

The Page_load event fires on every trip to your page, so you are overwriting
the data changed on the site with the Page_Load event assignments.
.... so, your fresh, new values are trampled on when you post back to
update...

events fired in this order:

Init
Load viewstate
Process postback data (this is where your new data gets back to the
application)
Load (this is were you lose the data, and the original values are put back)
Send postback Change
Postback events
pre-render
save view state
render
dispose
unload

Learn it, love it, live it! :)
 
A

Alex

Dave,

Many thanks...

The sequence of load instructions solve my problem...
Basically I have everything else done right... Except, not
checking explicitly for POST during Page_Load...

I was basically counting on the even handler to trigger
the event..

Thank you
Alex
 
L

Leonard

This event sequence, indeed, is discussed in several
ASP.NET with varying degrees of clarity. The major theme
in most books is to use the "if (!IsPostBack)..." logic to
get around the overwriting of variables in the viewstate.
However, I am observing a difference in behavior between
the asp:label control (where everything seems to work as I
expect and state is preserved via the viewstate) and the
asp:textbox where the state is not preserved in the
viewstate. What is happening here? I think Alex and I
are hitting the same problem.

Also, the instance of the asp:textbox seems not to have
been created in the init and when it is referenced in the
Page_Load an exception is thrown because the object isn't
there!

What is happening with the asp:textbox?
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top