473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HOW TO HIGHLIGHT TEXT WITHIN ASP CONTROL ON PAGE LOAD

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

Nov 19 '05 #1
2 1978
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" <pa***@qedsoftwaresolutions.com> wrote in message
news:11*********************@g14g2000cwa.googlegro 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

Nov 19 '05 #2
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.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: leegold2 | last post by:
Commonly done, eg. you enter a word in a search engine and when a hit-page comes up the search word(s) are highlighted. I'm doing a fulltext search that works well but I've tried a few "packaged...
0
by: NancyASAP | last post by:
In case anyone hasn't seen this problem, just sharing the info.... I created a dotnet 1.1 page with a literal control. I used a streamreader to open a text file to fill the control. I filled the...
2
by: dchow | last post by:
I would like to highlight (say make it bold) a couple of words in a Msgbox. Is it possible? Similarly, how can I change the caption of a label with highlighted text?
3
by: Nicky | last post by:
hi, all I have an iframe in my page. Actually what I want is just like the google search. When user clicks search, I will load the a page from another URL into iframe and then highlight the key...
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
2
by: Daniel Di Vita | last post by:
I have created an ASP.NET page that allows the user to page through a result set. I need to expand on this. On that same page I a filed where the user can type in a search string. When they click...
2
by: Number 11950 - GPEMC! Replace number with 11950 | last post by:
When you highlight a selection of text represented in an object on a form, somewhere in the Framework or alternatively in the Windows API there exists an array of variables that either contain as a...
0
Merlin1857
by: Merlin1857 | last post by:
A thing I have been asked for on a number of occasions is the ability to highlight text after its been searched for in a record return page. The following does this perfectly. Use this function...
3
by: yogarajan | last post by:
Dear Friends i am devloping for search box it is woking good i want highlight my search text. My original text is Mixed case (Lower case and upper case) my search text is lower case means how can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.