简体   繁体   中英

Server tag not evaluated in server control

On my ASPX page, I need a server control checkbox to pass a backend variable as a parameter in its onclick JS function. But it doesn't seem to work as expected.

Please refer the two checkboxes below:

<input type="checkbox" id="Checkbox1" onclick="ToggleMyOnly('<%=gsListID %>');" />
<input type="checkbox" id="Checkbox2" runat="server" onclick="ToggleMyOnly('<%=gsListID %>');" />

Here the Checkbox1 evaluates the value of gsListID as expected. However, Checkbox2 just passes it as is.

The only difference between these two controls is that Checkbox2 is a server control.

I have searched for a solution for this issue across many sites, but did not get an answer.

I also tried converting the Checkbox1 to an ASP checkbox as follows:

<asp:CheckBox ID="CheckboxASP" runat="server" Text="test" onclick="ToggleMyOnly('<%=gsListID %>');" />

But this also did not evaluate the server tag.

Can anyone help me know how to use the server tag in "onclick" for a server control input element? (Avoiding an ASP:checkbox preferred).

You should write like below:

 <asp:CheckBox runat="server" ID="chk" Text="Test" onchange="return ToggleMyOnly('<%=gsListID %>');" />

if you dont want to postback then return false from ToggleMyOnly function.

It's working from myside.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM