What is the id that Javascript uses for a server control?

M

mark4asp

When I view-source I see that ASP.NET 2 has given the control:
lstActivities no id but a
name="ctl00$ContentPlaceHolder$lstActivities"

How can I get the client-side id (or name) of a HTML element? (the id
that is seen by javascript). What should I put in between the server
tags: CheckStyle('<% %>') such that the div id="tdStyle" is displayed
when the ListBox has an item with text 'Awarded mandate'?

The function init runs when the page is loaded.

I realise that this can be done with server code but I have needed to
know the client-side ids of html elements in the past so I'll still
post the question.


<html>
<head>
<script type="text/javascript">
onload=init
function init()
{
CheckStyle('<% %>')
}
function CheckStyle(oSel)
{

document.getElementById('tdStyle').style.display=(oSel.options[oSel.selectedIndex].text=='Awarded
mandate')?'block':'none'
}
</script>
</head>
<body>
<asp:ListBox ID="lstActivities" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="lstActivities_SelectedIndexChanged"
onblur="CheckStyle(this)">
</asp:ListBox>

<div id="tdStyle" style="display: none;">
<strong>Style</strong><br /><br />
<asp:RadioButtonList ID="rblStyle" runat="server">
<asp:ListItem Text="Active" Value="A" />
<asp:ListItem Text="Passive" Value="P" />
<asp:ListItem Text="Unconstrained" Value="U" />
<asp:ListItem Text="Undisclosed" Value="N" />
</asp:RadioButtonList>
</div>
</body>
</html>
 

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,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top