Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Setting Focus in UserControl

Reply
Thread Tools

Setting Focus in UserControl

 
 
jason.pileski@pacourts.us
Guest
Posts: n/a
 
      03-11-2005
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("focu s",
strScript)
all within the 'OnItemComand' sub that is defined for the grid.

I have also tried
document.getElementById('myCom*ponents_dgdEdit__ct l2_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.

 
Reply With Quote
 
 
 
 
jason.pileski@pacourts.us
Guest
Posts: n/a
 
      03-16-2005
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.

http://www.velocityreviews.com/forums/(E-Mail Removed) 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("focu s",
> strScript)
> all within the 'OnItemComand' sub that is defined for the grid.
>
> I have also tried
>

document.getElementById('myCom*ponents_dgdEdit__ct l2_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.


 
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
emulating window.focus in Body onload() event and setting focus to a control on same page Jason ASP .Net 4 05-07-2007 05:54 PM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments