Selecting textbox contents

S

Strange Cat

Hi everyone

Is it possible to select the contents in an aspnet textbox? (Like the old
textbox selectstart and so on properties)

Thanx in advance
 
M

Martin Dechev

Hi, Strange Cat,

The TextBox is rendered to the client (the html that is sent to the browser)
as <input type="text"...>, <input type="password"...> or
<textarea></textarea> HTML element. So, you can set whatever client-side
properties, events, styles, etc. apply to these elements to your TextBox.

To access from the server-side (the code-behind) some specific event or
property of the HTML element that do not have corresponding properties of
the System.Web.UI.WebControls.TextBox class you should use the Attributes
property of this class.

http://msdn.microsoft.com/library/e...webcontrolswebcontrolclassattributestopic.asp

i.e. to assign some javascript function that will handle the onselectstart
event:

[C#]
textbox1.Attributes["onselectstart"] = "javascript:DoSomething();";
[VB.NET]
textbox1.Attributes("onselectstart") = "javascript:DoSomething();"

Hope this helps
Martin
 
S

Strange Cat

Thanx for answering Martin!

I dont think what you suggested would do what I need, tho:

Looks like your idea would fire an event when the user selects stuff inside
the textbox. What I'd like to do is to programmatically select stuff inside
the textbox (so that if the user types a key, the preexisting chars are
automatically cleared...).

Any idea?

Thanx

ASC
 
M

Malek

The behavior you are looking for needs to happen on the client side ...
Martin is right, even if he answered for the onselect event ... Whatever
will do your trick will have to be done on the client side (javascript,
DHTML ...)
If you do need to implement on the server side - round trip to the server -
, then you use just what Martin said, and then handle the selection event on
the server side to add the necessary attributes (selectstart, ...etc) and
send back to client ...
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top