Can I set initial focus from server-side into textbox?

Discussion in 'ASP .Net Web Controls' started by Kent P. Iler, May 4, 2005.

  1. Kent P. Iler

    Kent P. Iler Guest

    Hi,

    I am showing/hiding a variety of panels that have different text boxes via
    code-behind functions. Depending on the condition, I would like to have the
    focus be set on a specific text box. However, all examples I've seen do
    this from the client side.

    Does anyone have a way to easily to specify the textbox to focus on from a
    code-behind function? My guess is it will have to be some combination of
    server-side and client-side coding.

    Any help would be appreciated.

    Thanks!

    -- Kent Iler
    ----------------------------------------------------------------------

    Please CC: all replies via e-mail
    Remove .NOSPAM from e-mail address
     
    Kent P. Iler, May 4, 2005
    #1
    1. Advertising

  2. Kent P. Iler

    mavisahdas Guest

    Hi Kent,

    Yeah you can bring to the focus to some controls based on some condition. I
    believe you know how to bring the focus to a control using java script. What
    you need to do here is make that script to trigger from the code behind file.

    There are two ways to running the script from the code behind file.

    1. Printing the script using response.write.

    eg. Response.Write("<script>text1.focus()</script>")

    2. Using Page.RegisterStartupScript

    Page.RegisterStartupScript("foc", "text1.focus()")

    Page.RegisterStartupScript will execute the script.

    With regards,

    Sadha Sivam S,
    Microsoft Community Star,
    Sr. Software Engineer,
    Aspire Systems,
    www.dotnetspider.com


    "Kent P. Iler" wrote:

    > Hi,
    >
    > I am showing/hiding a variety of panels that have different text boxes via
    > code-behind functions. Depending on the condition, I would like to have the
    > focus be set on a specific text box. However, all examples I've seen do
    > this from the client side.
    >
    > Does anyone have a way to easily to specify the textbox to focus on from a
    > code-behind function? My guess is it will have to be some combination of
    > server-side and client-side coding.
    >
    > Any help would be appreciated.
    >
    > Thanks!
    >
    > -- Kent Iler
    > ----------------------------------------------------------------------
    >
    > Please CC: all replies via e-mail
    > Remove .NOSPAM from e-mail address
    >
    >
    >
     
    mavisahdas, May 4, 2005
    #2
    1. Advertising

  3. Something basic like this should work:

    Response.Write "<script language = javascript>"& MyTextBox.ClientID &
    ".focus()</script>"

    Here is an even slicker approach:
    http://SteveOrr.net/faq/2in1.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Kent P. Iler" <> wrote in message
    news:...
    > Hi,
    >
    > I am showing/hiding a variety of panels that have different text boxes via
    > code-behind functions. Depending on the condition, I would like to have
    > the focus be set on a specific text box. However, all examples I've seen
    > do this from the client side.
    >
    > Does anyone have a way to easily to specify the textbox to focus on from a
    > code-behind function? My guess is it will have to be some combination of
    > server-side and client-side coding.
    >
    > Any help would be appreciated.
    >
    > Thanks!
    >
    > -- Kent Iler
    > ----------------------------------------------------------------------
    >
    > Please CC: all replies via e-mail
    > Remove .NOSPAM from e-mail address
    >
     
    Steve C. Orr [MVP, MCSD], May 4, 2005
    #3
  4. Kent P. Iler

    mavisahdas Guest

    Hi Kent,

    You can make use form Data Format string property of the grid columns to
    format the date.

    For more input Refer http://www.dotnetspider.com/technology/kbpages/384.aspx.

    With regards,

    Sadha Sivam S,
    Microsoft Community Star,
    Sr. Engineer,
    Aspire Systems,
    www.dotnetspider.com

    "Kent P. Iler" wrote:

    > Hi,
    >
    > I am showing/hiding a variety of panels that have different text boxes via
    > code-behind functions. Depending on the condition, I would like to have the
    > focus be set on a specific text box. However, all examples I've seen do
    > this from the client side.
    >
    > Does anyone have a way to easily to specify the textbox to focus on from a
    > code-behind function? My guess is it will have to be some combination of
    > server-side and client-side coding.
    >
    > Any help would be appreciated.
    >
    > Thanks!
    >
    > -- Kent Iler
    > ----------------------------------------------------------------------
    >
    > Please CC: all replies via e-mail
    > Remove .NOSPAM from e-mail address
    >
    >
    >
     
    mavisahdas, May 4, 2005
    #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. Brian Henry

    setting initial focus to textbox

    Brian Henry, Jul 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    548
    Craig Deelsnyder
    Jul 4, 2004
  2. Kent P. Iler
    Replies:
    4
    Views:
    640
    =?Utf-8?B?bWF2aXNhaGRhcw==?=
    May 4, 2005
  3. Jack
    Replies:
    4
    Views:
    207
    Phillip Windell
    Nov 26, 2003
  4. Replies:
    2
    Views:
    357
    Thomas 'PointedEars' Lahn
    Jun 6, 2005
  5. Roger
    Replies:
    3
    Views:
    379
Loading...

Share This Page