Calling ClientID from aspx
14,806
Solution 1
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.
Solution 2
you could do that using jQuery like this:
var control = '#<%= chbSAveState.ClientID%>';
$(control).change(function(){
SaveState($(this).id);
});
Author by
euther
Updated on June 11, 2022Comments
-
euther almost 2 years
"")" />
that doesn't work, the error says: Parser Error Message: Server tags cannot contain <% ... %> constructs.
Any aproaches to solve this ? Thank you ;)
-
jball about 14 yearsWhy bother with jQuery for something so straight-forward?