how to implement an onclick on asp:TextBox?

  • Thread starter Thread starter Jan Hoffman
  • Start date Start date
J

Jan Hoffman

hi @all

I have the following element in an ascx-file:

<asp:TextBox id="name" runat="server">name</asp:TextBox>

The textbox belongs to an application of a telefonebook.
I want that if I click into the Textbox *once* that the text "name" is
selceted. at the moment I have to double-click.

any solutions to this problem?
thanks
Jan
 
Try this:
<asp:TextBox RunAt=Server Id="name" onClick="this.select();" />

hi @all

I have the following element in an ascx-file:

<asp:TextBox id="name" runat="server">name</asp:TextBox>

The textbox belongs to an application of a telefonebook.
I want that if I click into the Textbox *once* that the text "name" is
selceted. at the moment I have to double-click.

any solutions to this problem?
thanks
Jan
 
Jan,

It can be done in javascript on client side usind onclick event.

Eliyahu
 
hi Shiva,

thank you....it works
but visual studio 2003 does not recognize the onclick parameter in the HTML
view! that's why I thought it would not work :(

Jan
 
how can I impelent it with code behind?
Jan

Eliyahu Goldin said:
Jan,

It already had been discussed once. OnClick is not documented for server
controls. Use it if you are happy with using undocumented features.
Otherwise use Attributes["onclick"] in code-behind.

Eliyahu

Jan Hoffman said:
hi Shiva,

thank you....it works
but visual studio 2003 does not recognize the onclick parameter in the HTML
view! that's why I thought it would not work :(

Jan
 
Hi,
You use the Attributes collection: Text1.Attributes.Add ("onClick",
"this.select();"); // C#

how can I impelent it with code behind?
Jan

Eliyahu Goldin said:
Jan,

It already had been discussed once. OnClick is not documented for server
controls. Use it if you are happy with using undocumented features.
Otherwise use Attributes["onclick"] in code-behind.

Eliyahu

Jan Hoffman said:
hi Shiva,

thank you....it works
but visual studio 2003 does not recognize the onclick parameter in the HTML
view! that's why I thought it would not work :(

Jan
 
Jan,

It already had been discussed once. OnClick is not documented for server
controls. Use it if you are happy with using undocumented features.
Otherwise use Attributes["onclick"] in code-behind.

Eliyahu
 
One way is to put a line (c# syntax)

name.Attributes["onclick"]="this.select();"

in the page's PreRender event handler.

Eliyahu

Jan Hoffman said:
how can I impelent it with code behind?
Jan

Eliyahu Goldin said:
Jan,

It already had been discussed once. OnClick is not documented for server
controls. Use it if you are happy with using undocumented features.
Otherwise use Attributes["onclick"] in code-behind.

Eliyahu

Jan Hoffman said:
hi Shiva,

thank you....it works
but visual studio 2003 does not recognize the onclick parameter in the HTML
view! that's why I thought it would not work :(

Jan

Try this:
<asp:TextBox RunAt=Server Id="name" onClick="this.select();" />

hi @all

I have the following element in an ascx-file:

<asp:TextBox id="name" runat="server">name</asp:TextBox>

The textbox belongs to an application of a telefonebook.
I want that if I click into the Textbox *once* that the text "name" is
selceted. at the moment I have to double-click.

any solutions to this problem?
thanks
Jan
 

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

Back
Top