|
-
Apr 21st, 2005, 08:23 AM
#1
Thread Starter
Junior Member
Webcontrols.Textbox Problem in retrieving text
Hi all, I'm new to ASP.NET, can you give me a hand?
I have a Web Form with a WebControls.Button and a WebControls.Textbox on it, and with the following code behind:
VB Code:
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 = "Enter Text Here"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("You have entered :" & TextBox1.Text)
End Sub
I would like to set the text on the textbox object in the Load Event, and it's up to user modification.
After all, it should display the modifided text upon clicking the button.
Sounds simple isn't it?
But to my surpeise, TextBox1.text remains the initial value (i.e "Enter Text Here"), and it ignores users' modification. Can somebody advise on it?
-
Apr 21st, 2005, 08:40 AM
#2
Fanatic Member
Re: Webcontrols.Textbox Problem in retrieving text
Did you save your changes before running it?
Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment. 
-
Apr 21st, 2005, 08:56 AM
#3
Thread Starter
Junior Member
Re: Webcontrols.Textbox Problem in retrieving text
 Originally Posted by simonm
Did you save your changes before running it?
Do you mean saving the project/aspx, etc files, before rebuilding the solution? yes i did.
-
Apr 21st, 2005, 09:02 AM
#4
Thread Starter
Junior Member
Re: Webcontrols.Textbox Problem in retrieving text
I found something related to the problem:
If the Textbox control has NOT been assigned a value to its text property programtically (i.e textbox1.text ="something"), there won't be such a problem.
however, when TextboxBox1.text has been set by code, the problem raised
-
Apr 21st, 2005, 09:58 AM
#5
Re: Webcontrols.Textbox Problem in retrieving text
VB Code:
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 = "Enter Text Here"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write("You have entered :" & TextBox1.Text)
End Sub
-
Apr 21st, 2005, 10:00 AM
#6
Frenzied Member
Re: Webcontrols.Textbox Problem in retrieving text
The problem is you are setting the value of the TextBox on Page_Load. When the button is clicked, it causes the form to be posted again and a new Page_Load which sets the text back to the original.
-
Apr 21st, 2005, 12:43 PM
#7
Thread Starter
Junior Member
Re: Webcontrols.Textbox Problem in retrieving text
Oh, that works!
Thanks mendhak and wey97!
-
Apr 21st, 2005, 12:55 PM
#8
New Member
Re: Webcontrols.Textbox Problem in retrieving text
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 = "Enter Text Here"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Textbox1.text = Response.Write("You have entered :" & TextBox1.Text)
End Sub
I know this has already been solved but i thought i would post also that you could do it this way.....this should work
-
Apr 21st, 2005, 01:23 PM
#9
Thread Starter
Junior Member
Re: Webcontrols.Textbox Problem in retrieving text
Thanks webprog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|