Yep I know both will the same thing. But therotically the syntax of document.getElementById("<%=element.ClientID%>") must work which is not working, in my case.
Could you plz let us know how the code is not working.
is is showing a javascript error or what?
What it is showing if you use alert(document.getElementById('<%= YourServerControl.ClientID %>'));
The output should be object.
Joydeep Sen
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
using alert(document.getElementById('<%= YourServerControl.ClientID %>')); is returning null to me. I myself think it should return object but thats not happening.
Joydeep Sen
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
Yep I know both will the same thing. But therotically the syntax of document.getElementById("<%=element.ClientID%>") must work which is not working, in my case.
That won't work if you are using included JavaScript files. In other words, that will ONLY work if the JavaScript is actually and physically inside of the markup.
I think that it is showing null because when you are calling that method that time that control has not been rendered.
In that case javascript shows null. Check that if you are calling the method before the control gets rendered in the page properly or not.
Joydeep Sen
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
varun5318
Member
6 Points
18 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 11:33 AM|LINK
Yep I know both will the same thing. But therotically the syntax of document.getElementById("<%=element.ClientID%>") must work which is not working, in my case.
joydeepsen
Contributor
4155 Points
802 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 11:48 AM|LINK
hi varun,
Could you plz let us know how the code is not working.
is is showing a javascript error or what?
What it is showing if you use alert(document.getElementById('<%= YourServerControl.ClientID %>'));
The output should be object.
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
varun5318
Member
6 Points
18 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 12:06 PM|LINK
Joy,
using alert(document.getElementById('<%= YourServerControl.ClientID %>')); is returning null to me. I myself think it should return object but thats not happening.
joydeepsen
Contributor
4155 Points
802 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 12:12 PM|LINK
varun,
Put your javascript code like below,
onload=function()
{
alert(document.getElementById('<%= YourServerControl.ClientID %>'));
}
Let me know the status
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
varun5318
Member
6 Points
18 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 12:30 PM|LINK
Joy,
Actually I am working with MasterPage, so i have created a seprate funciton as -
function funTest(){alert(document.getElementById(
"<%=TxtDrawnOn.ClientID%>"));}and called it onclick="funTest()" of div element. It is returning null.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 12:39 PM|LINK
That won't work if you are using included JavaScript files. In other words, that will ONLY work if the JavaScript is actually and physically inside of the markup.
NC...
joydeepsen
Contributor
4155 Points
802 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 26, 2009 12:43 PM|LINK
Hi Varun,
I think that it is showing null because when you are calling that method that time that control has not been rendered.
In that case javascript shows null. Check that if you are calling the method before the control gets rendered in the page properly or not.
Dont forget to click “Mark as Answer” on the post that helped you.This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
varun5318
Member
6 Points
18 Posts
Re: javascript working on my machine (application server), but not on client.
Mar 28, 2009 06:00 AM|LINK
Thanks buddy,
You have correctly said, document.getElementByID("<%=TxtDrawnOn.ClientID%>") is working once i have included the JavaScript with HTML markup.
Is there any way to get the client id of a control in external JavaScript file? Or in external file I always have to write"tl00_ContentPlaceHolder1_TxtDrawnOn".
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: javascript working on my machine (application server), but not on client.
Mar 30, 2009 11:30 AM|LINK
You have to build your JavaScript for include files so that the ID is passed to each function by the caller. For example:
A function that currently looks like this:
function someFunction()
{
var elementRef = document.getElementById('<%= someElement.ClientID %>');
...
and called by: ClientScript.RegisterStartupScript(this.GetType(), "script-key-goes-here", "someFunction();", true);
Must now look like this:
function someFunction(elementId)
{
var elementRef = document.getElementById(elementId);
...
and called by: ClientScript.RegisterStartupScript(this.GetType(), "script-key-goes-here", "someFunction('" + someElement.ClientID + "');", true);
NC...