Selecting textbox contents

Discussion in 'ASP .Net' started by Strange Cat, Feb 23, 2004.

  1. Strange Cat

    Strange Cat Guest

    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
    Strange Cat, Feb 23, 2004
    #1
    1. Advertising

  2. 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
    "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
    >
    >
    Martin Dechev, Feb 23, 2004
    #2
    1. Advertising

  3. Strange Cat

    Strange Cat Guest

    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
    Strange Cat, Feb 23, 2004
    #3
  4. Strange Cat

    Malek Guest

    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
    >
    >
    Malek, Feb 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JMC
    Replies:
    0
    Views:
    433
  2. Red_Indian
    Replies:
    5
    Views:
    2,525
    Red_Indian
    May 25, 2004
  3. Don Adams
    Replies:
    1
    Views:
    572
    Martin Honnen
    Mar 5, 2004
  4. Kamarulnizam Rahim
    Replies:
    4
    Views:
    200
    Robert Klemme
    Jan 28, 2011
  5. Replies:
    0
    Views:
    174
Loading...

Share This Page