473,324 Members | 2,166 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,324 software developers and data experts.

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 1268
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="MyUserControl"
In I.E. the Textbox will now have the ID
MyUserControl_tb

So when you have javascript thats referring to this ID, it will stop working
untill you change this to refer to MyUserControl_tb.
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*****@granite-ridge.com> wrote in message
news:eJ**************@TK2MSFTNGP14.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.UniqueID

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

document.GetElementByID('" + btnMyButton.UniqueID + "')
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***@workshare.com> wrote in message
news:u2*************@TK2MSFTNGP15.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="MyUserControl"
In I.E. the Textbox will now have the ID
MyUserControl_tb

So when you have javascript thats referring to this ID, it will stop
working untill you change this to refer to MyUserControl_tb.
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*****@granite-ridge.com> wrote in message
news:eJ**************@TK2MSFTNGP14.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***@workshare.com> wrote:
I think .. THINK .. if you creating your JavaScript from your Code Behind,
when you try do something like
document.GetElementByID('btnMyButton');
swap this for

document.GetElementByID('" + btnMyButton.UniqueID + "')
and it should use the right ID


Why can't you just use:
document.GetElementByID('btnMyButton.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="javascript">";
MyJScript += "function something() { document.GetElementByID('" +
btnMyButton.UniqueID + "');}";
MyJScript += "</script>";

Page.RegisterClientScriptBlock("SomeKey", MyJScript");
as btnMyButton.UniqueID is a c# function, not a JavaScript function

"Steve Murphy" <sm*****@granite-ridge.com> wrote in message
news:ej**************@TK2MSFTNGP14.phx.gbl...

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

document.GetElementByID('" + btnMyButton.UniqueID + "')
and it should use the right ID


Why can't you just use:
document.GetElementByID('btnMyButton.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
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...
8
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...
4
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.