Is there a way to change the ClientID of a control?

S

Stoyan Stratev

I have a control whose ClientID is used in a number of Javascript routines.
It turned out that the ClientID has a dash (-) in it and breaks the JS. Is
there a way to change the ClientID of that control?
 
M

Michel de Becdelièvre

Stoyan Stratev said:
I have a control whose ClientID is used in a number of Javascript routines.
It turned out that the ClientID has a dash (-) in it and breaks the JS. Is
there a way to change the ClientID of that control?

yes and no :

doing ipt.ID = "newid" in code behind will change the ID, but the name
will still be a built name with the resulting ClientID being of the form :
"parentID1_parentID2_newid".

this is apparently needed for ASP.Net to be able to rebuild control
hierarchies out of the postback information.

note that parentID1 will only be present if parent1 is with
runat="server", DOM nodes that are not runat="server" are ignored.
 
L

Lars-Erik Aabech

The ClientID should only get underscores, unless you have used a dash in the
ID of the control. ASP.NET uses underscores to concat ID's in the control
hierarchy to create unique ClientID's and colons to create unique form name
attributes (UniqueID).

Are you sure nothing in your control hierarchy has a dash in the ID?

Lars-Erik
 
S

Stoyan Stratev

This happens in a DotNetNuke environment. I checked the chain of controls
and due to a bug in the DNN core the ID of the grandparent control contains
a dash. So I am pretty much stuck if I cannot modify my ClientID. Modifying
the grandparent's ID has no effect.
 
L

Lars-Erik Aabech

Hi again!

DotNetNuke is open source, isn't it? Can you do a search/replace on the
granparent's id and replace the dash with an underscore? (If you use the
binaries only, try getting the source and compile your own version)

L-E
 
H

Hans Kesting

Stoyan said:
I have a control whose ClientID is used in a number of Javascript
routines. It turned out that the ClientID has a dash (-) in it and
breaks the JS. Is there a way to change the ClientID of that control?

maybe you can change the JS:
instead of something like "document.elements.my-control-with-dashes.value",
use "document.elements["my-control-with-dashes"].value"
Or use getElementByID("my-control-with-dashes")

Hans Kesting
 
S

Stoyan Stratev

the problem is that I am distributing a skin object. This means that the
client has the javascript and Dotnetnuke already installed. I cannot modify
them. If I change the DNN core then all users would also have to recompile
the whole system which is not feasable.
It seems that I have to wait for the next release of DNN where they will
have (hopefully) the bug fixed.
 
L

Lars-Erik Aabech

Sounds like a plan, but check out Hans Kesting's answer to your post.. Might
work :)

L-E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top