Get text in TextBox without pressing Enter key

  • Thread starter Thread starter mg
  • Start date Start date
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 ...
 
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
 
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





.
 
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 ...


.
 
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
 
Back
Top