Control ID Name

  • Thread starter Thread starter OldButStillLearning
  • Start date Start date
O

OldButStillLearning

I want to write some javascript attached to some event. When the event
fires, I want to pass the name of a ASP.Net Control to the javascript. I
happen to be working in a web page which has a master page. What I notice is
that when the page is rendered the ID's of all of the ASP.Net controls are
altered with what appears to be a prefix. How can I know the ID name so that
my javascript can do a "document.getElementById(controlIDName)"?
 
var ctl = document.getElmentById('<%= myControl.ClientID %>');

-- bruce (sqlwork.com)
 
OldButStillLearning said:
I want to write some javascript attached to some event. When the event
fires, I want to pass the name of a ASP.Net Control to the javascript. I
happen to be working in a web page which has a master page. What I notice
is
that when the page is rendered the ID's of all of the ASP.Net controls are
altered with what appears to be a prefix. How can I know the ID name so
that
my javascript can do a "document.getElementById(controlIDName)"?

Well,

if you're writing javascript code directly in the aspx page you can use
something like this:

....
<asp:textbox id="txtBox" runat="server" .../>

...

<script language="javascript" type="text/javascript">
var clientVisibleTextBox =
document.GetElementById('<%=txtBox.ClientId%>');
...
</script>
 
Back
Top