473,385 Members | 1,642 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,385 software developers and data experts.

UserControl run Javascript

How can I make a UserControl run some javascript when it loads? this is so
the control sets focus to a textbox it contains.

TIA!
Nov 19 '05 #1
3 5248
Hi,

This will do it, just add it to the load event of your User Control:

If (Page.IsClientScriptBlockRegistered("Focus") = False) Then
MyBase.Page.RegisterStartupScript("Focus", "<script
language='javascript'>document.getElementById('" + TextBox1.ClientID +
"').focus();</script>")
End If

Be sure to use control.ClientID and not just hard code the control id
because ASP.Net will change the control id inside a User Control to somthing
like "_ctl0_controlid". Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"TCORDON" <tc******@hotmail.com> wrote in message
news:OI*************@TK2MSFTNGP09.phx.gbl...
How can I make a UserControl run some javascript when it loads? this is so
the control sets focus to a textbox it contains.

TIA!

Nov 19 '05 #2
I added de code you gave me, but I dont know if I am doing something wrong,
the focus is not being set. This is how my conde looks now:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If (Page.IsClientScriptBlockRegistered("Focus") = False) Then

MyBase.Page.RegisterStartupScript("Focus",
"<scriptlanguage='javascript'>document.getElementB yId('" + txtLinea.ClientID
+ "').focus();</script>")

End If

End Sub
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uO**************@TK2MSFTNGP15.phx.gbl...
Hi,

This will do it, just add it to the load event of your User Control:

If (Page.IsClientScriptBlockRegistered("Focus") = False) Then
MyBase.Page.RegisterStartupScript("Focus", "<script
language='javascript'>document.getElementById('" + TextBox1.ClientID +
"').focus();</script>")
End If

Be sure to use control.ClientID and not just hard code the control id
because ASP.Net will change the control id inside a User Control to
somthing
like "_ctl0_controlid". Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"TCORDON" <tc******@hotmail.com> wrote in message
news:OI*************@TK2MSFTNGP09.phx.gbl...
How can I make a UserControl run some javascript when it loads? this is
so
the control sets focus to a textbox it contains.

TIA!


Nov 19 '05 #3
Hi,

There needs to be a space here between "script" and "language" :
"<scriptlanguage='javascript'>document.getElementB yId('" + txtLinea.ClientID

If it still doesn't work then do a view source on your page and post the
outputted HTML. It'll be just above the clsoing </form> tag. Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"TCORDON" <tc******@hotmail.com> wrote in message
news:ex**************@TK2MSFTNGP14.phx.gbl... I added de code you gave me, but I dont know if I am doing something wrong, the focus is not being set. This is how my conde looks now:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If (Page.IsClientScriptBlockRegistered("Focus") = False) Then

MyBase.Page.RegisterStartupScript("Focus",
"<scriptlanguage='javascript'>document.getElementB yId('" + txtLinea.ClientID + "').focus();</script>")

End If

End Sub
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uO**************@TK2MSFTNGP15.phx.gbl...
Hi,

This will do it, just add it to the load event of your User Control:

If (Page.IsClientScriptBlockRegistered("Focus") = False) Then
MyBase.Page.RegisterStartupScript("Focus", "<script
language='javascript'>document.getElementById('" + TextBox1.ClientID +
"').focus();</script>")
End If

Be sure to use control.ClientID and not just hard code the control id
because ASP.Net will change the control id inside a User Control to
somthing
like "_ctl0_controlid". Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"TCORDON" <tc******@hotmail.com> wrote in message
news:OI*************@TK2MSFTNGP09.phx.gbl...
How can I make a UserControl run some javascript when it loads? this is
so
the control sets focus to a textbox it contains.

TIA!



Nov 19 '05 #4

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

Similar topics

4
by: Rob Koch | last post by:
What's the best way to refresh a usercontrol using a parameter? My usercontrol is just a DataList that retrieves data from SQL in association with a public propterty. I click on a LinkButton in...
2
by: bill yeager | last post by:
When trying to run my web project, I get the following error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the...
2
by: Carlo Marchesoni | last post by:
I have a UserControl that builds a Tree-View Menu using Javascript. This UC does not run as a ServerControl Then, in every aspx page I include this UC. Everything works perfect, except that if I...
4
by: Dan | last post by:
Hi, I have a UserControl that contain : 1 treeview 1 datagrid and so on ... Is there a way to postback ONLY ONE control and not all content in my Usercontrol ? (because all contents in my...
5
by: Lau Lei Cheong | last post by:
Hello, I'm writing a usercontrol to be included in my project. The usercontrol have a few javascript function to do the client-side tasks. However, the controls on the usercontrol seems to...
2
by: Jimmy | last post by:
Hi How do you refer from you webpage to a usercontrol which contains a n html control with javascript? usercontrol contains: <input id="tb1" name="tb1" type=text>
1
by: freshRecruit | last post by:
Hi, I am having a problem, and is driving me nuts and my deadline is fast approaching. Please do help me.. This is a webapplication with a usercontrol which has some buttons for adding,...
0
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
5
by: tshad | last post by:
I get an error when running my Javascript inside my UserControl. It works fine if I put the UserControl Data directly in my Web Page. The stripped down code is: <script language=javascript>...
2
by: jyanmin.fang | last post by:
Hi, In my current project, I need to embed an .NET winform usercontrol in the aspx page (via <Objecttag). This winform usercontrol has an event called DoEvent (void DoEvent()). This winform...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.