views:

207

answers:

3

Hi, i have this:

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

that doesn't work, the error says: Parser Error Message: Server tags cannot contain <% ... %> constructs.

Any aproaches to solve this ? Thank you ;)

A: 

I don't have much experience with server side controls, but perhaps:

<input type="checkbox" id="chbSaveState" runat="server" tabindex="3" 
onchange="SaveState(chbSaveState.ClientID)" />
RedFilter
+3  A: 

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.

jball
thank you very much for your time. Apreciate it ;)
rolando
* * Glad to help!
jball
A: 

you could do that using jQuery like this:

var control = '#<%= chbSAveState.ClientID%>';
$(control).change(function(){
    SaveState($(this).id);
});
VinTem
Why bother with jQuery for something so straight-forward?
jball