Get text in TextBox without pressing Enter key

M

mg

I want to enter characters in a TextBox in a WebForm,
press a Button in the WebForm, and read the characters
that were typed into the TextBox from within the
Button_Click event handler. The main point here is that I
want to read the value typed into the TextBox without
hitting the Enter key or setting focus on another
control ...
 
D

dj Bass

double clicking on the button in the design view that you want to use will
provide you with the event handler you require, alternatively you can just
create a empty method which would look something like this:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

end sub.


then, say your edit box has the id = "editBoxText". You'll be able to call
the editBoxText.Text() method on that member variable created for that
control and access the text.

is that what you wanted or did i miss the boat?

if you want to set the focus from the submit button back to the edit box,
check out this website for a short method on setting focus...

http://aspnetweblog.com/posts/7115.aspx
 
S

S. Justin Gengo

mg,

Then the code that dj Bass just gave you is what you want.

You get the text with:

MyTextBox.Text

Justin


mg said:
I have an event handler for the button click event. What I
need is [C#] code to place in this event handler. The code
needs to read the characters in the TextBox without my
having [physically] pressed the enter key after entering
the characters in the TextBox or having given another
control focus by pressing on it with the mouse.

-----Original Message-----
double clicking on the button in the design view that you want to use will
provide you with the event handler you require, alternatively you can just
create a empty method which would look something like this:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

end sub.


then, say your edit box has the id = "editBoxText". You'll be able to call
the editBoxText.Text() method on that member variable created for that
control and access the text.

is that what you wanted or did i miss the boat?

if you want to set the focus from the submit button back to the edit box,
check out this website for a short method on setting focus...

http://aspnetweblog.com/posts/7115.aspx





.
 
D

dj Bass

Unless you expect the event handler for a button to simply pick up the text
from the text box as you write? which wouldn't work, you'd need an event
handler for the text box on the text change event...

as they say in Zulu, angaas.

S. Justin Gengo said:
mg,

Then the code that dj Bass just gave you is what you want.

You get the text with:

MyTextBox.Text

Justin


mg said:
I have an event handler for the button click event. What I
need is [C#] code to place in this event handler. The code
needs to read the characters in the TextBox without my
having [physically] pressed the enter key after entering
the characters in the TextBox or having given another
control focus by pressing on it with the mouse.

-----Original Message-----
double clicking on the button in the design view that you want to use will
provide you with the event handler you require, alternatively you can just
create a empty method which would look something like this:

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

end sub.


then, say your edit box has the id = "editBoxText". You'll be able to call
the editBoxText.Text() method on that member variable created for that
control and access the text.

is that what you wanted or did i miss the boat?

if you want to set the focus from the submit button back to the edit box,
check out this website for a short method on setting focus...

http://aspnetweblog.com/posts/7115.aspx


I want to enter characters in a TextBox in a WebForm,
press a Button in the WebForm, and read the characters
that were typed into the TextBox from within the
Button_Click event handler. The main point here is that I
want to read the value typed into the TextBox without
hitting the Enter key or setting focus on another
control ...


.
 
V

Vikram.NET

Hi,

It is not clear what you actually want to do.

You have said that after entering text in the textbox, you
will be pressing a Button in the web form. When you press
the button obviously, the textbox control will lose focus
and the Button will get focus.

As far as getting the text of the textbox is concerned, it
can be done very easily by writing the event handler for
Button's Click event as follows:

private void Button1_Click(object sender,
System.EventArgs e)
{
string Value;
Value = TextBox1.Text;
}

Value will contain the text entered in the textbox.

Regards,
Vikram
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top