Newbie question concerning page load event

G

Guest

Hello,

I was looking at this sample asp page:

-----------------------------------
<Script Runat="Server">

Sub Page_Load
lblMessage.Text = ""
End Sub

Sub txtSomeText_TextChanged( s As Object, e As EventArgs )
lblMessage.Text = "You changed the value!"
End Sub

</Script>

<html>
<head><title>TextBoxChanged.aspx</title></head>
<body>

<form Runat="Server">

<asp:TextBox
ID="txtSomeText"
Text="Apple"
OnTextChanged="txtSomeText_TextChanged"
Runat="Server"/>

<asp:Button
Text="Submit!"
Runat="Server"/>

<p>
<asp:Label
id="lblMessage"
Runat="Server" />

</form>

</body>
</html>
-----------------------------------

The text that goes along with this sample says that you need to clear the
text of the text box on page load or else it will always say "You changed the
value!" even if you didn't (due to viewsate).

My question is, why doesn't the page load event trigger the text box's
TextChanged event? You are changing the text box's text.

Thanks,
-Flack
 
G

Guest

Hi:

I believe that's because the viewstate keeps all the state of the object's
page.
The second time you call the page the values will be rewriten.

--
Thales - Services Division
Bulnes 2756 P.5 - C1425DKX
Ciudad Autónoma de Buenos Aires
Tel.: (+5411) 4806-9146
Fax.: (+5411) 4807-0563
 
S

sam

I believe i understand your question.

Text changed is not defined to fire for changes you make
programatically on the server. Technically, what happens is the text
box's posted form value is compared with the view state restored value
(which occurs in LoadViewState phase). If they are different a change
event is raised (in RaiseChangedEvents phase). It doesn't care about
changes you make on the server.

I don't know how much you already understand about it, but you
absolutely have to understand the page lifecycle to understand asp.net
(although this question doesn't really touch on that) .Here is a good
link
http://aspalliance.com/articleViewer.aspx?aId=134&pId=
 
T

TDAVISJR

Does the textbox have a autopostback property. If so set it to true and see
what happens.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top