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());

       ….

}

 

 

相关文章:

  • 2021-06-09
  • 2021-06-30
  • 2021-12-30
  • 2021-06-08
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-01-14
  • 2021-09-03
  • 2021-07-26
  • 2021-06-05
相关资源
相似解决方案