您的位置:首页 > Web前端 > JavaScript

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

2007-08-17 19:28 721 查看
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">[/b]

<title>NO TITLE</title>

<script language="javascript">

function refreshPage()

{

window.Open(‘OneWebPage.aspx?para=<% =variable %>[/b]’);

}

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

….

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐