Calling ClientID from aspx

asp.net, c#, clientid

Solution

You're calling a JS event (`onchange`), not a server event, so just pass in `this.id`.

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3"  
onchange="SaveState(this.id)" /> 

To be clear, `this.id` and `<%=chbSaveState.ClientID%>` will return the same value in this case. Since you're calling this on an event of `chbSaveState`, you can just use the easily accessible JS property here, rather than `<%=chbSaveState.ClientID%>`, which requires the server to return the id which is generated by the server for that control.

Problem

"")" /> that doesn't work, the error says: Parser Error Message: Server tags cannot contain <% ... %> constructs. Any aproaches to solve this ? Thank you ;)

Original source