简体   繁体   English

服务器标签未在服务器控件中评估

[英]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. 在我的ASPX页面上,我需要一个服务器控件复选框以将后端变量作为其onclick JS函数中的参数传递。 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. 在这里,Checkbox1按预期评估gsListID的值。 However, Checkbox2 just passes it as is. 但是,Checkbox2只是按原样传递它。

The only difference between these two controls is that Checkbox2 is a server control. 这两个控件之间的唯一区别是Checkbox2是服务器控件。

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: 我还尝试将Checkbox1转换为ASP复选框,如下所示:

<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? 谁能帮助我知道如何在服务器控件输入元素中使用“ onclick”中的服务器标签? (Avoiding an ASP:checkbox preferred). (避免使用ASP:复选框)。

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. 如果您不想回发,则从ToggleMyOnly函数返回false。

It's working from myside. 从我这边开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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