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

  • Thread starter Thread starter Stoyan Stratev
  • Start date Start date
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?
 
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.
 
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
 
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.
 
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
 
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
 
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.
 
Sounds like a plan, but check out Hans Kesting's answer to your post.. Might
work :)

L-E
 
Back
Top