防止嵌入的 ASP 代码被转义

Prevent Embedded ASP Code from being escaped

这个看起来与 here 提出的问题相似,但 OP 提出的场景看起来不同,因为他接受的答案不符合我的 requirement.In 我的情况,我正在尝试嵌入一​​个 asp 片段作为从按钮的 onclick 调用的 Javascript 方法的参数,但结果是标签在编译时被转义。 ASP 代码是:

<asp:Button runat="server" ID="Calculate_Mean" Text="Calculate Mean" 
OnClientClick="mean('<%$TextBoxA.ClientID + ',' + TextBoxB.ClientID + ',' +
TextBoxC.ClientID%>')"

我得到的结果是:

<input type="submit" name="Calculate_Mean" 
value="Calculate Mean"
onclick="mean(&#39;&lt;%=TextBoxA.ClientID%>&#39;);" id="Calculate_Mean" />

我已参考并尝试了以下页面,但仍无法解决问题:

Passing ASP.net control to JS Function
Different Embedded ASP Code Blocks and its uses

编辑:这是呈现页面的屏幕截图:

也许您可以为 html 按钮更改 asp:button:

<button  onclick="mean( document.getElementById('<%=TextBoxA.ClientID%>'));" ></button>

或者尝试在 js 函数中获取客户端 ID:

ASPX

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function mean() {
            var a = document.getElementById('<%=TextBoxA.ClientID%>');
            var b = document.getElementById('<%=TextBoxB.ClientID%>');
            var c = document.getElementById('<%=TextBoxC.ClientID%>');
            alert(a.value);
            alert(b.value);
            alert(c.value);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBoxA" runat="server" ></asp:TextBox>
                <asp:TextBox ID="TextBoxB" runat="server" ></asp:TextBox>
                <asp:TextBox ID="TextBoxC" runat="server"  ></asp:TextBox>
    <asp:Button runat="server" ID="Calculate_Mean" Text="Calculate Mean" 
        OnClientClick="mean();" />
    </div>
    </form>
</body>
</html>