473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript with User Control

I'd like to package a navigation bar into a user control. The problem I'm
having is getting the rollover buttons to work. Where do I place the
Javascript for the image caching and switching for the rollover effect? I'm
using image buttons.

Thanks in advance,
Steve Murphy
Nov 19 '05 #1
4 1283
I would place the JavaSCript in the Control itself.

I've often had problems with JavaScript in UserControls, as they are renamed
when placed onto the ASPX page.
When you register your ASPX page, and give your tag a name, in the output
HTML that goes to INternet explorer, you controls are renamed the tag name
followed by the ID you specified.

So if you have a textbox:
<asp:TextBox id="tb"
and you register your usercontrol
TagName="MyUser Control"
In I.E. the Textbox will now have the ID
MyUserControl_t b

So when you have javascript thats referring to this ID, it will stop working
untill you change this to refer to MyUserControl_t b.
Now this becomes a bit silly, because that ID name is based on its instance
in a given ASPX page, and cannot be generalised.

There was a post a few days ago about how to get the controls name from the
code and then generate the JavaScript there with thee right ID;s
I'm just gonna dig that up (cause i need it to for future reference), and
will post shortly

HTH

"Steve Murphy" <sm*****@granit e-ridge.com> wrote in message
news:eJ******** ******@TK2MSFTN GP14.phx.gbl...
I'd like to package a navigation bar into a user control. The problem I'm
having is getting the rollover buttons to work. Where do I place the
Javascript for the image caching and switching for the rollover effect?
I'm using image buttons.

Thanks in advance,
Steve Murphy

Nov 19 '05 #2
ok, found it

This i have not tested, but will next time i have this problem

btnMyButton.Uni queID

I think .. THINK .. if you creating your JavaScript from your Code Behind,
when you try do something like
document.GetEle mentByID('btnMy Button');
swap this for

document.GetEle mentByID('" + btnMyButton.Uni queID + "')
and it should use the right ID

The same logic would go for ImageButtons with rollovers - if you need to
reference the ImageButtons ID

HTH

"Grant Merwitz" <gr***@workshar e.com> wrote in message
news:u2******** *****@TK2MSFTNG P15.phx.gbl...
I would place the JavaSCript in the Control itself.

I've often had problems with JavaScript in UserControls, as they are
renamed when placed onto the ASPX page.
When you register your ASPX page, and give your tag a name, in the output
HTML that goes to INternet explorer, you controls are renamed the tag name
followed by the ID you specified.

So if you have a textbox:
<asp:TextBox id="tb"
and you register your usercontrol
TagName="MyUser Control"
In I.E. the Textbox will now have the ID
MyUserControl_t b

So when you have javascript thats referring to this ID, it will stop
working untill you change this to refer to MyUserControl_t b.
Now this becomes a bit silly, because that ID name is based on its
instance in a given ASPX page, and cannot be generalised.

There was a post a few days ago about how to get the controls name from
the code and then generate the JavaScript there with thee right ID;s
I'm just gonna dig that up (cause i need it to for future reference), and
will post shortly

HTH

"Steve Murphy" <sm*****@granit e-ridge.com> wrote in message
news:eJ******** ******@TK2MSFTN GP14.phx.gbl...
I'd like to package a navigation bar into a user control. The problem I'm
having is getting the rollover buttons to work. Where do I place the
Javascript for the image caching and switching for the rollover effect?
I'm using image buttons.

Thanks in advance,
Steve Murphy


Nov 19 '05 #3

"Grant Merwitz" <gr***@workshar e.com> wrote:
I think .. THINK .. if you creating your JavaScript from your Code Behind,
when you try do something like
document.GetEle mentByID('btnMy Button');
swap this for

document.GetEle mentByID('" + btnMyButton.Uni queID + "')
and it should use the right ID


Why can't you just use:
document.GetEle mentByID('btnMy Button.UniqueID ')

Why do you need to wrap it?

Thanks,
Steve Murphy

Nov 19 '05 #4
I was referring to the code behind where you would build up the jscript then
register it on the page

string MyJScript = "<Script language="javas cript">";
MyJScript += "function something() { document.GetEle mentByID('" +
btnMyButton.Uni queID + "');}";
MyJScript += "</script>";

Page.RegisterCl ientScriptBlock ("SomeKey", MyJScript");
as btnMyButton.Uni queID is a c# function, not a JavaScript function

"Steve Murphy" <sm*****@granit e-ridge.com> wrote in message
news:ej******** ******@TK2MSFTN GP14.phx.gbl...

"Grant Merwitz" <gr***@workshar e.com> wrote:
I think .. THINK .. if you creating your JavaScript from your Code
Behind,
when you try do something like
document.GetEle mentByID('btnMy Button');
swap this for

document.GetEle mentByID('" + btnMyButton.Uni queID + "')
and it should use the right ID


Why can't you just use:
document.GetEle mentByID('btnMy Button.UniqueID ')

Why do you need to wrap it?

Thanks,
Steve Murphy

Nov 19 '05 #5

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

Similar topics

2
2594
by: New User | last post by:
I have a System.Web.UI.UserControl as custom control and I have a javascript block for user control. The problem is I want to bring src attribute from outside as property or other method. e.g <script language="JavaScript" src="Scripts/filename.js"></script> When I register this control (drop control) on aspx page different than current folder in other words, when I have
8
4024
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form has a Button. When the Button is clicked, I want a JavaScript confirm dialog to pop-up with the options 'OK' & 'Cancel'. I have done this using the following code: Sub Page_Load(....) btnClick.Attributes.Add("OnClick", "javascript:return...
4
4235
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user control.. but if i add javascript in page in which i am adding user control then that javascript is executed properly. i tested by displaying alert message in javascript. can anyone tell
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.