Aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" %>
<html>
<head><title>UpdatePanel Call Javascript</title></head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel10" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
.cs代码
protected void Button1_Click(object sender, EventArgs e)
{
//GoToListPage();
string url = “pageList.aspx”;
string js = "document.location.href ='" + url + "'";
//string js = "alert('aa')";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "returnPageList", js, true);
}
注意:js代码不能写成如下格式(页面提示错误)
即不能加"<script language=javascript></script>“
public void ShowMessage(Type type, ClientScriptManager scriptManager, string message)
{
if (!string.IsNullOrEmpty(message))
{
scriptManager.RegisterStartupScript(type, "back", "<script language=javascript>alert('"+message+"');</script>");
}
}