zoukankan      html  css  js  c++  java
  • One tip for javascript to invoke variables in asp.net web page

    One tip for javascript to invoke variables in asp.net web page

     

    Here’s what I used in an asp.net web page.

     

    <head runat="server">

        <title>NO TITLE</title>

        <script language="javascript">

                  function refreshPage()

                  {

                       window.Open(OneWebPage.aspx?para=<% =variable %>);

                  }            

        </script>

    </head>

    <body onload="<%=refereshPage%>">

    ……

    This will raise the following error:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

     

    This is an asp.net web page --- <head runat=”server”> --- is raising the exception and we can not remove the tag runat=”server” from the head element when using ASP.NET 2.0 themes. Thus, we can not use ServerVariables with expressions to dynamically assign a parameter, or we have to remove runat=”server” and stop using themes.

     

    There is one solution for this issue. Refer to the following code snippet in PAGE_LOAD method.

     

    protected string bodyOnLoad = @"javascript:window.open('OneWebPage.aspx?para=@variable');";

     

    protected void Page_Load(object sender, System.EventArgs e)

    {

           ….

           bodyOnLoad = bodyOnLoad.Replace("@variable", ONEPARAMETER.ToString());

           ….

    }

     

     

  • 相关阅读:
    day-11函数的形参与实参
    day-10初级函数
    .检查用户名是否使用接口
    04.vue发送短信逻辑
    03.celery发送短信接口
    02.celery配置与基本使用
    Celery介绍
    python爬虫与Django框架vue交互的前后端代码详情(励志人生网实例)
    爬虫找工作之面试题(2)
    爬虫找工作之面试题(1)
  • 原文地址:https://www.cnblogs.com/rickie/p/860212.html
Copyright © 2011-2022 走看看