473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Simplest possible question?

qqq
Ok, what's wrong with this picture? I have a simple webform with a single
textbox webcontrol and a single webcontrol button. When the form is
displayed, I manually type some new text into the textbox. Why aren't my
updates detected in the button's code?!

[It makes no difference how I set AutoPostBack or EnableViewState]

Thanks, Paul.
-------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

TextBox1.Text = "Init value goes in here"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

TextBox2.Text = TextBox1.Text '<<This always detects ""Init value goes in
here" even if I've edited it on-screen!!

End Sub
Nov 20 '05 #1
2 987
Change Page_Load to this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then
TextBox1.Text = "Init value goes in here"
End If

End Sub

A simple question, gets a simple answer. :)

Greg
"qqq" <qq*@qqq.com> wrote in message
news:ee**************@tk2msftngp13.phx.gbl...
Ok, what's wrong with this picture? I have a simple webform with a single
textbox webcontrol and a single webcontrol button. When the form is
displayed, I manually type some new text into the textbox. Why aren't my
updates detected in the button's code?!

[It makes no difference how I set AutoPostBack or EnableViewState]

Thanks, Paul.
-------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

TextBox1.Text = "Init value goes in here"

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

TextBox2.Text = TextBox1.Text '<<This always detects ""Init value goes in
here" even if I've edited it on-screen!!

End Sub

Nov 20 '05 #2
"qqq" <qq*@qqq.com> wrote in message news:ee**************@tk2msftngp13.phx.gbl...
Ok, what's wrong with this picture? I have a simple webform with a single
textbox webcontrol and a single webcontrol button. When the form is
displayed, I manually type some new text into the textbox. Why aren't my
updates detected in the button's code?!


Because on every Page_Load you are initializing TextBox1.Text to "Init value goes in here",
therefore whatever you typed (which ASP.NET put into TextBox1.Text prior to Page_Load)
is overwritten by the assignment. After Page_Load, the Button1_Click event fires, and it
will always see "Init value goes in here."

What you probably want to do in Page_Load is only initialize the TextBox1.Text on the first
request to the page (and not re-initialize it on subsequent requests, because the viewstate of
the TextBox will retain it's value).

If ( Not Page.IsPostBack ) Then
TextBox1.Text = "Init value goes in here"
End If
Derek Harmon
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jslowery | last post by:
Hello, I'm new to both PostgreSQL and psycopg and I'm trying to connect to my database running on localhost. I have postgres setup to do md5 authentication and this works when using a db admin tool...
10
by: Rich Hephner | last post by:
Why isn't this working? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;...
4
by: Alan Silver | last post by:
Hello, I have a site that stores some info in an XML file. The file is pretty simple, of the form... <Site> <SiteName>Fred's Ferrets</SiteName> <SomeVar>Whatever</SomeVar> .... etc ......
3
by: | last post by:
For a given web form, I want to know what the +simplest+ way to add an attribute to all of a particular control type on that page. For example, I might want to add an onClick attribute to all...
82
by: Eric Lindsay | last post by:
I have been trying to get a better understanding of simple HTML, but I am finding conflicting information is very common. Not only that, even in what seemed elementary and without any possibility...
1
by: Dave Johnson | last post by:
greetings, can anyone show an example of aggregation in any .net code vb.net or C# i guess it shouldnt be that hard but i searched a lot without finding anything that explains the...
1
by: giannis | last post by:
I want when i click on a button "fill" a DataGridView with data from a "SELECT" SQL clause. What the simplest way to achieve this work with the use of the available bindingSource (without make...
2
by: stef | last post by:
hello, I'm still in the transition of going from MatLab to Scipy, and installed previous week a SciPy on a PC twice, through the new "Enstaller". It's a pitty that there will be no old...
2
by: shah0101 | last post by:
Hi there, I don't know how appropriate is my question but I know the problem that I have to install a software on my server and my landing page (home page) must be in PHP to run the software...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.