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());
….
}
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());
….
}
相关文章推荐
- The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the ser
- [ZT]Submitting Web Form data from one ASP.NET page to another
- How to invoke Java web service in ASP.net using C#
- Embed client-side JavaScript in an ASP.NET 1.1 web page from server side code
- [GOOD Article] How to disable web.config Inheritance for Child Applications in Subfolders in ASP.NET?
- ComponentOne WebChart for ASP.NET基础
- ASP.NET 4.5.256 has not been registered on the Web server. You need to manually configure your Web server for ASP.NET 4.5.256 in order for your site to run correctly
- JS:Trim() in javascript, how to define a function of checkinput for a WebControl(ascx)
- Adding the Test API in The ASP.NET Web API Help Page
- How to programmatically assign a SkinID to a control while using a master page in ASP.net 2.0
- Culture and UI Culture for ASP.NET Web Page
- How to implement scrolling image with javascript in web page
- ComponentOne WebChart for ASP.NET基础(2)
- Adding the Test API in The ASP.NET Web API Help Page
- To JavaScript Prompts for Buttons in Asp::DataGrid for Delete Column(ZT)
- To JavaScript Prompts for Buttons in Asp::DataGrid for Delete Column(ZT)
- Creating a NuGet Package in 7 easy steps - Plus using NuGet to integrate ASP.NET MVC 3 into existing Web Forms applications
- How to load the specified mscordacwks.dll for managed debugging when multiple .NET runtime are loaded in one process
- ComponentOne WebChart for ASP.NET基础(3)
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net