how to implement an onclick on asp:TextBox?

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
 
S

Shiva

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
 
E

Eliyahu Goldin

Jan,

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

Eliyahu
 
J

Jan Hoffman

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
 
J

Jan Hoffman

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
 
S

Shiva

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
 
E

Eliyahu Goldin

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
 
E

Eliyahu Goldin

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top