Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

HOW TO HIGHLIGHT TEXT WITHIN ASP CONTROL ON PAGE LOAD

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parm - 28 Oct 2005 01:14 GMT
How do I highlight text in my first (tabindex = 1) asp control (eg:
textbox) on the webform on page load. If I try to set focus using
javascript then I get script error "Cannot move focus to invisible
control)". Because the tabindex of first control is 1 therfore I can
get the focus on first control but the text inside is not highlighted.
Any help would be greatly appriciated.

My set focus javascript:
   Public Sub SetFocus(ByRef MyPage As System.Web.UI.Page, _
                       ByVal objMyObject As Object)

       Dim ctrLiteralControl As LiteralControl

       On Error GoTo ErrorMsg

       ctrLiteralControl = _
                   New LiteralControl("<script language=JavaScript>" &
_
                   "document.getElementById('" & objMyObject.ID &
"').focus();" & _
                   "document.getElementById('" & objMyObject.ID &
"').select();" & _
                   "</script>")
       MyPage.Controls.Add(ctrLiteralControl)
   End Sub
Rick Strahl [MVP] - 28 Oct 2005 09:30 GMT
I suspect you're not putting that code in the right place. You should put
that code just before the </form> tag to run when the page loads, or call
the function from the body onload event.

If the error you're getting is accurate it sounds like your control is
actually not visible in which case you can't set focus. Otherwise that
should work - I use the same approach, although I've built it into my custom
Page class.

Select is IE specific I think... but since you're using VBScript I guess
you're targeting IE anyway.

+++ Rick ---

Signature

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog

> How do I highlight text in my first (tabindex = 1) asp control (eg:
> textbox) on the webform on page load. If I try to set focus using
[quoted text clipped - 21 lines]
>        MyPage.Controls.Add(ctrLiteralControl)
>    End Sub
parm - 28 Oct 2005 22:42 GMT
Hi Rick,

My javascript to set focus is within a vb.net function called
SetFocus(). I am calling this function from vb.net page load event.
Because the page is not loaded when the SetFocus() function is called
therefore I am getting the above error message. I also call the same
SetFoucs() function from other places in my code and it works fine. I
just cannot get it to work on page load. I am calling some other
function on body onload event + my javascript is embeded in vb.net
function.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.