This is a migrated thread and some comments may be shown as answers.

[Solved] ClientID and masterpage issue

3 Answers 159 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Adam Hubble
Top achievements
Rank 1
Adam Hubble asked on 07 Apr 2009, 10:43 AM
Hi, I keep having to write bits of javascript that use the following:
 
document.getElementById("<%=somecontrolfield.ClientID%>");

Now, this should be ok, BUT it appears that master pages do not like it at all. I get a runtime error saying "could not find somefield" if I try to use the above in content pages.

In the meantime I have reverted to doing this:

 document.getElementById("ct100_ContentPlaceHolder1_somedetailsview_somecontrolfield");

Now this works, but it could obviously get broken if the masterpage changes and I would rather use the first code. Is this possible with content/master pages? I can't find an answer and seem to be needing one quite a lot for radajax things like radwindow etc.

Thanks,
Matt

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Apr 2009, 01:47 PM
Hello Matt,

Where is the problematic code snippet defined, is it in the same ContentPlaceHolder as the "somecontrolfield" control?

Additionally, please try wrapping your client-code into a RadCodeBlock/RadScriptBlock control as described here and see if it makes any difference.

Let me know how it goes.

All the best,
Iana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Adam Hubble
Top achievements
Rank 1
answered on 07 Apr 2009, 02:50 PM
Hi Iana,

Yes, the control is within a detailsview and the detailsview is within the contentplaceholder.

The javascript is located at the base of the contentplaceholder.

I have tried wrapping a radcodeblock around it but now I get a compilation error - controlname (cntLinkHiddenField) not declared.

The javascript is a simple script for a custom validator

function ReqValHf(source, args) {
    var name= document.getElementById("<%=cntLinkHiddenField.ClientID%>");
if (name.value.length <= 0) {args.IsValid = false;} else {args.IsValid = true;} return; }

Thanks,
Matt



0
Iana Tsolova
Telerik team
answered on 08 Apr 2009, 07:42 AM
Hello Matt,

In this case, would it be convenient for you to open a formal support ticket in order to send me the problematic content and master pages. I could then have a better look on your scenario and setup and try finding what could be the reason for the javascript errors.
Thank you for your cooperation in advance.

All the best,
Iana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Adam Hubble
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Adam Hubble
Top achievements
Rank 1
Share this question
or