javascript 获取错误 Error-Server 标签不能包含 <% ... %> 结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15699895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error Error-Server tags cannot contain <% ... %> constructs
提问by Prince Antony G
<input id="tbxPopupCode" type="text" runat="server" value="<%= Request.QueryString["code"].Replace("-"," ") %>" />
I m getting an error:
我收到一个错误:
Server tags cannot contain <% … %> constructs
服务器标签不能包含 <% ... %> 结构
I need to replace the value from Request.QueryString["code"]
and bind into textbox value.
我需要替换值Request.QueryString["code"]
并绑定到文本框值。
回答by Andreas Niedermair
Actually, the exception message is pretty clear:
You can not have runat="server"
and <%= %>
.
实际上,异常消息非常清楚:您不能拥有runat="server"
和<%= %>
。
There are some workarouns for this (eg <%# %>
), but why not simply setting the value on the code-behind like this.tbxPopupCode.Value = ...
?
对此有一些解决方法(例如<%# %>
),但为什么不简单地在代码隐藏上设置值,例如this.tbxPopupCode.Value = ...
?
回答by David
I know that it doesn't apply to this specific question, but I also received this error when I included the construct for an HTML tag attribute inside of a PlaceHolder control.
我知道它不适用于这个特定问题,但是当我在 PlaceHolder 控件中包含 HTML 标记属性的构造时,我也收到了这个错误。