Setting Focus in UserControl

Discussion in 'ASP .Net Datagrid Control' started by jason.pileski@pacourts.us, Mar 11, 2005.

  1. Guest

    I have an editable datagrid as part of a usercontrol. When I click the
    Edit button, I wish for focus to be set on the first control, a
    dropdownlist. I have underlying javascript that I found elsewhere here
    but it does not appear to work.

    <script language="javascript">
    <!--
    frm.myComponents_dgdEdit__ctl2­_txtBox.focus();
    frm.myComponents_dgdEdit__ctl2­_txtBox.select();
    //-->
    </script>

    "myComponents_dgdEdit__ctl2_tx­tBox" is retrieved by FindControl and
    using the ClientID property.


    I placed this code in a string variable, strScript, and then performed
    CType(sender, DataGrid).Parent.Page.Register­StartupScript("focus",
    strScript)
    all within the 'OnItemComand' sub that is defined for the grid.

    I have also tried
    document.getElementById('myCom­ponents_dgdEdit__ctl2_txtBox')­.focus();

    to no avail. What I found equally as puzzling is that while the focus
    was not set, the data in the textbox was selected telling me the
    ..select() worked.

    If someone could point me in the right direction or tell me what I'm
    doing wrong, I'd appreciate it!

    Any feedback would be appreciated.
     
    , Mar 11, 2005
    #1
    1. Advertising

  2. Guest

    I solved my own problem. The page itself has smartnavigation turned
    on. This doesn't generate the id and name attributes that the
    javascript uses to set the focus.

    wrote:
    > I have an editable datagrid as part of a usercontrol. When I click

    the
    > Edit button, I wish for focus to be set on the first control, a
    > dropdownlist. I have underlying javascript that I found elsewhere

    here
    > but it does not appear to work.
    >
    > <script language="javascript">
    > <!--
    > frm.myComponents_dgdEdit__ctl2­_txtBox.focus();
    > frm.myComponents_dgdEdit__ctl2­_txtBox.select();
    > //-->
    > </script>
    >
    > "myComponents_dgdEdit__ctl2_tx­tBox" is retrieved by FindControl and
    > using the ClientID property.
    >
    >
    > I placed this code in a string variable, strScript, and then

    performed
    > CType(sender, DataGrid).Parent.Page.Register­StartupScript("focus",
    > strScript)
    > all within the 'OnItemComand' sub that is defined for the grid.
    >
    > I have also tried
    >

    document.getElementById('myCom­ponents_dgdEdit__ctl2_txtBox')­.focus();
    >
    > to no avail. What I found equally as puzzling is that while the

    focus
    > was not set, the data in the textbox was selected telling me the
    > .select() worked.
    >
    > If someone could point me in the right direction or tell me what I'm
    > doing wrong, I'd appreciate it!
    >
    > Any feedback would be appreciated.
     
    , Mar 16, 2005
    #2
    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. huobazi
    Replies:
    1
    Views:
    720
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    435
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,564
  4. Jason
    Replies:
    4
    Views:
    1,652
    Jason
    May 7, 2007
  5. Roger
    Replies:
    3
    Views:
    351
Loading...

Share This Page