I have aspx pages which uses repetitive code. So I put them on a masterfile and referring that in all other files. I have used the <asp:Content ID> in all other pages where I included master page like,
<asp:Content ID="Step1Content" ContentPlaceHolderID="MainContent" Runat="Server">
My issue is now all the field id’s has a suffix of ContentPlaceHolderID_fieldName and because of this my javascript doesn’t work.
<input id='chkRaces_1' type='checkbox' runat='server' onclick="enableShow50();" /><label for='chkRaces_1'>American Indian or Alaska Native</label><br />
When I debug, it appears like,
<input id="MainContent_chkRaces_1" type="checkbox" onclick="enableShow50(<%# Eval(chkRaces_1.ClientID) %>);" name="ctl00$MainContent$chkRaces_1">
and my Javascript which refrences using id='chkRaces_1' fails. I thought of replacing all the inputs with <asp:ListItem> tags n so, but I get error."type HtmlInputCheckBox" is not compatible with "ListItem". So I got to change the class too which I don’t want to.
What else I can do to achieve the same with minimal change in aspx.
You can use ClientIDMode, but keep in mind that’s only available in .NET 4.0 and above.
Or in JavaScript:
if you are trying to access the control in javascript, then using .ClientID is probably your best bet, as it doesn’t require change in aspx page