屬性和方法如下:
屬性/方法
|
描述
|
AllowCustomError
|
和Web.config中的自定義錯誤配置區<customErrors>相聯繫,是否使用它,默認值爲true
|
AsyncPostBackErrorMessage
|
異步回傳發生錯誤時的自定義提示錯誤信息,
|
AsyncPostBackTimeout
|
異步回傳時超時限制,默認值爲90,單位爲秒
|
EnablePartialRendering
|
是否支持頁面的局部更新,默認值爲True,一般不需要修改
|
ScriptMode
|
指定ScriptManager發送到客戶端的腳本的模式,有四種模式:Auto,Inherit,Debug,Release,默認值爲Auto,後面會仔細說到。
|
ScriptPath
|
設置所有的腳本塊的根目錄,作爲全局屬性,包括自定義的腳本塊或者引用第三方的腳本塊。如果在Scripts中的<asp:ScriptReference/>標籤中設置了Path屬性,它將覆蓋該屬性。
|
OnAsyncPostBackError
|
異步回傳發生異常時的服務端處理函數,在這裏可以捕獲一場信息並作相應的處理。
|
OnResolveScriptReference
|
指定ResolveScriptReference事件的服務器端處理函數,在該函數中可以修改某一條腳本的相關信息如路徑、版本等。
|
<script runat="server">
void DropDownSelection_Change(Object sender, EventArgs e)
{
Calendar1.DayStyle.BackColor =
System.Drawing.Color.FromName(ColorList.SelectedItem.Value);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>ScriptManager Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1"
ShowTitle="True"
runat="server" />
<div>
Background:
<br />
<asp:DropDownList ID="ColorList"
AutoPostBack="True"
OnSelectedIndexChanged="DropDownSelection_Change"
runat="server">
<asp:ListItem Selected="True" Value="White">
White </asp:ListItem>
<asp:ListItem Value="Silver">
Silver </asp:ListItem>
<asp:ListItem Value="DarkGray">
Dark Gray </asp:ListItem>
<asp:ListItem Value="Khaki">
Khaki </asp:ListItem>
<asp:ListItem Value="DarkKhaki"> D
ark Khaki </asp:ListItem>
</asp:DropDownList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form>
</body>
</html>
<deployment retail="false" />
</system.web>
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<script runat="server">
protected void ErrorProcessClick_Handler(object sender, EventArgs e)
{
// This handler demonstrates an error condition. In this example
// the server error gets intercepted on the client and an alert is shown.
throw new ArgumentException();
}
protected void SuccessProcessClick_Handler(object sender, EventArgs e)
{
// This handler demonstrates no server side exception.
UpdatePanelMessage.Text = "The asynchronous postback completed successfully.";
}
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager1.AsyncPostBackErrorMessage = "異常信息爲:" + e.Exception.Message;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>PageRequestManager endRequestEventArgs Example</title>
<style type="text/css">
body {
font-family: Tahoma;
}
#AlertDiv{
left: 40%; top: 40%;
position: absolute; width: 200px;
padding: 12px;
border: #000000 1px solid;
background-color: white;
text-align: left;
visibility: hidden;
z-index: 99;
}
#AlertButtons{
position: absolute;
right: 5%;
bottom: 5%;
}
</style>
</head>
<body id="bodytag">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"
OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
</asp:ScriptManager>
<script type="text/javascript" language="javascript">
var divElem = 'AlertDiv';
var messageElem = 'AlertMessage';
var errorMessageAdditional = 'Please try again.';
var bodyTag = 'bodytag';
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function ToggleAlertDiv(visString)
{
if (visString == 'hidden')
{
$get(bodyTag).style.backgroundColor = 'white';
}
else
{
$get(bodyTag).style.backgroundColor = 'gray';
}
var adiv = $get(divElem);
adiv.style.visibility = visString;
}
function ClearErrorState() {
$get(messageElem).innerHTML = '';
ToggleAlertDiv('hidden');
}
function EndRequestHandler(sender, args)
{
if (args.get_error() != undefined && args.get_error().httpStatusCode == '500')
{
var errorMessage = args.get_error().message
args.set_errorHandled(true);
ToggleAlertDiv('visible');
$get(messageElem).innerHTML = '"' +
errorMessage + '" ' + errorMessageAdditional;
}
}
</script>
<asp:UpdatePanel runat="Server" UpdateMode="Conditional" ID="UpdatePanel1">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
<asp:Label ID="UpdatePanelMessage" runat="server" />
<br />
Last update:
<%= DateTime.Now.ToString() %>
.
<br />
<asp:Button runat="server" ID="Button1" Text="Submit Successful Async Postback"
OnClick="SuccessProcessClick_Handler" OnClientClick="ClearErrorState()" />
<asp:Button runat="server" ID="Button2" Text="Submit Async Postback With Error"
OnClick="ErrorProcessClick_Handler" OnClientClick="ClearErrorState()" />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div id="AlertDiv">
<div id="AlertMessage">
</div>
<br />
<div id="AlertButtons" >
<input id="OKButton" type="button" value="OK"
runat="server" onclick="ClearErrorState()" />
</div>
</div>
</form>
</body>
</html>
<Services>
<asp:ServiceReference Path="Service.asmx"/>
</Services>
</asp:ScriptManager>
public class WebServiceSample : System.Web.Services.WebService {
public WebServiceSample()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string EchoString(String s)
{
return "Hello " + s;
}
}
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript" language="JavaScript">
function OnbuttonGo_click()
{
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event
);
return false;
}
function OnRequestComplete(result)
{
alert(result);
}
</script>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebServiceSample.asmx"/>
</Services>
</asp:ScriptManager>
<div>
<input type="text" id="inputName" size=20/>
<input id="button" type="button" value="調 用" onclick="return OnbuttonGo_click()" /></div>
</form>
</body>
</html>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
ServiceReference sr = new ServiceReference();
sr.Path = "WebServiceSample.asmx";
ScriptManager1.Services.Add(sr);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript" language="JavaScript">
function OnbuttonGo_click()
{
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event
);
return false;
}
function OnRequestComplete(result)
{
alert(result);
}
</script>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<input type="text" id="inputName" size=20/>
<input id="button" type="button" value="調 用" onclick="return OnbuttonGo_click()" /></div>
</form>
</body>
</html>
示例代碼下載:http://www.cnblogs.com/Files/Terrylee/ASPNETAJAXScriptManagerDemo.rar
runat="server">
<AuthenticationService Path="" />
<ProfileService LoadProperties="" Path="" />
<Scripts>
<asp:ScriptReference/>
</Scripts>
<Services>
<asp:ServiceReference />
</Services>
</asp:ScriptManager>