我正在尝试向网站中的所有网页添加Javascript。因此,我创建了一个基页,网站上的大多数页面都是使用<@Reference
标记从此页面继承的。这是我的基页样本
<%@ Page Language="C#" CodeBehind="BasePage.aspx.cs" Inherits="MyProj.BasePage" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body ID="BasePage_Body" runat="server">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
在basepage.aspx.cs中我使用如下..
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Adding this Client Side script for my Page
if (<someCondition>)
{
BasePage_Body.Attributes.Add("onunload", "HandleClose()");
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "MWGBrowserhandlingClose",
"<script language=\"JavaScript\">" +
"function HandleClose() {" +
"alert(\"Killing the session on the server!!\");" +
"PageMethods.AbandonSession();" +
"} </script>");
}
}
但是我得到了BasePage_Body
的Nullreference异常。有关此为何以及如何解决的任何输入。
提前致谢