what doesn’t work, the error says: Parser error message: server tags cannot contain <% ...%> constructors. ...">

Calling ClientID from aspx

")" / ">

what doesn’t work, the error says: Parser error message: server tags cannot contain <% ...%> constructors.

Any attempts to solve this? Thanks;)

+4
source share
3 answers

You are calling the JS event ( onchange ), not the 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 are calling this on the chbSaveState event, you can simply use the easily accessible JS property here, rather than <%=chbSaveState.ClientID%> , which requires the server to return the identifier that the server generates for this control.

+10
source

you can do it with jQuery like this:

 var control = '#<%= chbSAveState.ClientID%>'; $(control).change(function(){ SaveState($(this).id); }); 
+2
source

I do not have much experience with server-side controls, but it is possible:

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

Source: https://habr.com/ru/post/1302270/


All Articles