How to make the text in TexbBox selected

  • Thread starter Thread starter ad
  • Start date Start date
I have done that , but it is no effect
My code is:

protected void Page_Load(object sender, EventArgs e)
{
TextBox3.Attributes["onfocus"] = "this.selected()";
}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox3.Focus();
}

But after I click Button1, the text in TextBox3 is not selected.


Eliyahu Goldin said:
TextBox renders as <input type=text ...>. This element has a method
select(). Setup a client-side onfocus event like this (c# syntax):

myTextBox.Attributes["onfocus"]="this.selected()";

Eliyahu

ad said:
I want the text in a TextBox selected when the TextBox get focus.
How can I do that?
 
TextBox renders as <input type=text ...>. This element has a method
select(). Setup a client-side onfocus event like this (c# syntax):

myTextBox.Attributes["onfocus"]="this.selected()";

Eliyahu
 
sorry, should be

TextBox3.Attributes["onfocus"] = "this.select()";

What is Focus()? Are you talking about a web form or a windows form? Or is
it something new in asp.net 2.0?

In asp.net 1.1 you can set focus on a control only on client side.

Eliyahu

ad said:
I have done that , but it is no effect
My code is:

protected void Page_Load(object sender, EventArgs e)
{
TextBox3.Attributes["onfocus"] = "this.selected()";
}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox3.Focus();
}

But after I click Button1, the text in TextBox3 is not selected.


Eliyahu Goldin said:
TextBox renders as <input type=text ...>. This element has a method
select(). Setup a client-side onfocus event like this (c# syntax):

myTextBox.Attributes["onfocus"]="this.selected()";

Eliyahu

ad said:
I want the text in a TextBox selected when the TextBox get focus.
How can I do that?
 
Thanks
It do well.
I use Focus() in Asp.Net 2.0.
It mybe the new feature in 2.0.

I have another question.
How to make "enter" key do as "tab" key in Web form.
My users is used "Enter" key to jump from controls to controls.



Eliyahu Goldin said:
sorry, should be

TextBox3.Attributes["onfocus"] = "this.select()";

What is Focus()? Are you talking about a web form or a windows form? Or is
it something new in asp.net 2.0?

In asp.net 1.1 you can set focus on a control only on client side.

Eliyahu

ad said:
I have done that , but it is no effect
My code is:

protected void Page_Load(object sender, EventArgs e)
{
TextBox3.Attributes["onfocus"] = "this.selected()";
}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox3.Focus();
}

But after I click Button1, the text in TextBox3 is not selected.


Eliyahu Goldin said:
TextBox renders as <input type=text ...>. This element has a method
select(). Setup a client-side onfocus event like this (c# syntax):

myTextBox.Attributes["onfocus"]="this.selected()";

Eliyahu

I want the text in a TextBox selected when the TextBox get focus.
How can I do that?
 
Back
Top