【问题标题】:asp.net c# javascript The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)asp.net c# javascript 控件集合无法修改,因为控件包含代码块(即<% ... %>)
【发布时间】:2016-09-24 05:48:06
【问题描述】:

我正在使用带有 javascript 的 Asp.net c#
我想在 javascript 中使用 Session 值,所以我使用这个代码:

<script type="text/javascript">
    var Warehousename = '<%= Session["warehouse_id"] %>';
    var temp = new Array();
    temp = Warehousename.split(",");
    if (temp.length > 1) {
        alert('you have multiple access of warehouse. Kindly select the only one warehouse from Preference')
        window.location.href = "frm_preferences.aspx";
    }
</script>

但我面临一些错误,例如

'控件集合无法修改,因为控件 包含代码块(即 )。'

请问哪里做错了,请指教

【问题讨论】:

  • 这段代码在哪里?在头部?
  • 是的,这段代码在头部

标签: javascript c# asp.net


【解决方案1】:

以下是可能的解决方案:

第一:
从页面的标题部分删除 JavaScript 并将其添加到页面的正文并运行您的应用程序,它将为您工作!

第二:

将代码块替换为&lt;%# 而不是&lt;%=

在将代码块替换为&lt;%# 而不是&lt;%= 后,在页面加载中添加以下代码

protected void Page_Load(object sender, EventArgs e)
{
  Page.Header.DataBind();    
}  

【讨论】:

  • 感谢您的好评。此解决方案适用于脚本标签,但不适用于链接标签。你知道为什么吗?
猜你喜欢
  • 2013-05-25
  • 2011-06-27
  • 2012-01-02
  • 1970-01-01
相关资源
最近更新 更多