Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Selecting textbox contents

Reply
Thread Tools

Selecting textbox contents

 
 
Strange Cat
Guest
Posts: n/a
 
      02-23-2004
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


 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      02-23-2004
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/en...butestopic.asp

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

[C#]
textbox1.Attributes["onselectstart"] = "javascriptoSomething();";
[VB.NET]
textbox1.Attributes("onselectstart") = "javascriptoSomething();"

Hope this helps
Martin
"Strange Cat" <> wrote in message
news:Oul_b.11764$...
> 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
>
>



 
Reply With Quote
 
 
 
 
Strange Cat
Guest
Posts: n/a
 
      02-23-2004
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


 
Reply With Quote
 
Malek
Guest
Posts: n/a
 
      02-23-2004
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 ...

"Strange Cat" <> wrote in message
news:Oul_b.11764$...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
if innerHTML used twice then it replaces the contents i want it to display all the contents virendra.amritkar@gmail.com Javascript 0 06-29-2007 08:13 AM
Selecting contents of TEXTAREA by default Red_Indian HTML 5 05-25-2004 07:51 AM
Re: Auto-highlighting (and selecting) editable table cell contents JMC Java 0 04-01-2004 08:41 AM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57