Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HOW TO HIGHLIGHT TEXT WITHIN ASP CONTROL ON PAGE LOAD

Reply
Thread Tools

HOW TO HIGHLIGHT TEXT WITHIN ASP CONTROL ON PAGE LOAD

 
 
parm
Guest
Posts: n/a
 
      10-28-2005
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

 
Reply With Quote
 
 
 
 
Rick Strahl [MVP]
Guest
Posts: n/a
 
      10-28-2005
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 ---

--

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

"parm" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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
>



 
Reply With Quote
 
 
 
 
parm
Guest
Posts: n/a
 
      10-28-2005
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.

 
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
Highlight & Replace Text, Add Footer & Page Number in PDF Docs sherazam Java 0 12-08-2010 10:25 AM
How do I make a text bar that users can scroll through and be able to highlight the text?!?!! loshbolton@hotmail.com HTML 1 03-10-2006 10:40 PM
How to highlight (change background color) of selected text within a text area omidalavi@yahoo.com Javascript 0 09-23-2005 04:34 PM
How do you Highlight text within asp:textbox? Michael SL ASP .Net Web Controls 1 02-13-2004 09:11 PM
Can not highlight text in a textbox on a ASP.net Page Robert M ASP .Net 1 01-05-2004 10:04 PM



Advertisments