scriptmanager
ScriptManager 控件包括在ASP.NET 2.0 AJAX Extensions中,它用来处理页面上的所有组件以及页面局部更新,生成相关的客户端代理脚本以便能够在JavaScript中访问Web Service,所有需要支持ASP.NET AJAX的ASP.NET页面上有且只能有一个ScriptManager控件。在ScriptManager控件中我们可以指定需要的脚本库,或者指定通过JS来调用的Web Service,以及调用AuthenticationService和ProfileService,还有页面错误处理等。
runat ="server" >
< AuthenticationService Path ="" />
< ProfileService LoadProperties ="" Path ="" />
< Scripts >
<asp:ScriptReference/>
</ Scripts >
< Services >
< asp:ServiceReference />
</ Services >
</ asp:ScriptManager >
ScriptManager 属性和方法如下:
属性/方法
|
描述
|
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 >
scriptmanager相关推荐
- 服务器标记“asp:ScriptManager”不明确。
转载的哦,解决了我遇到的问题了,好用~~~ 首先说下原先的情况,就是原本老项目的Web解决方案是使用.net framework 2.0的老版本, 所以机器也安装过Microsoft ASP.NET ...
- ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 区别
ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...
- ScriptManager 帮助您实现 Web 应用程序的 AJAX 功能
本文讨论: ScriptManager 在 ASP.NET AJAX 中的作用 ScriptManager 的隐式使用和显式使用 ASP.NET AJAX 对 Web 服务的支持 ASP.NET AJ ...
- 通过Ajax来简单的实现局部刷新(主要为C#中使用的UpdatePanel控件和ScriptManager控件)...
1. ScriptManager和UpdatePanel控件联合使用可以实现页面局部异步刷新的效果.UpdatePanel用来设置页面中局部异步刷新的区域,它必须依赖于ScriptManager,因为 ...
- ScriptManager调用 无参数WebService
在工程中添加一个 webservice 使用默认的 红色部分为后添加 为了要让ScriptManager识别这个WEBSERVICE WebService.cs using System; using ...
- 服务器控件的异步请求——UpdatePanel和ScriptManager
aspx文件里面有以下一段代码 <body><form id="form1" runat="server"><div>< ...
- ScriptManager同时存在于两个dll中的问题
错误 44 类型"System.Web.UI.ScriptManager"同时存在于 "c:\WINDOWS\assembly\GAC_MSIL\System.Web.E ...
- 关于scriptManager与JS代码兼容问题
在后台代码中: ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TimeInvalid", ...
- ScriptManager.RegisterAsyncPostBackControl 方法
来源:VS2012帮助文档 用途: 将控件注册为异步回发的触发器 语法: public void RegisterAsyncPostBackControl(Control control ) 参数 c ...
- Page.ClientScript、ClientScript、ScriptManager、ClientScriptManager等的详细解说
在 .aspx.cs页面中,输入这四个东西:Page.ClientScript.ClientScript.ScriptManager.ClientScriptManager,均会出提示,表示它们均可用 ...
最新文章
- oracle修改时区无效,Oracle 时区问题
- StackOverflow上面 7个最好的Java答案
- 常用的数据统计Sql 总结(转)
- Python环境出现模块找不到
- hdu2276 矩阵构造
- VS2005+WINDDK+Driver Studio 3.2编译出第一个测试驱动程序
- 修改SAP系统字段描述的方法
- boost::hana::remove_at_c用法的测试程序
- 删除msconfig启动项不打勾的东西
- git 创建 本地 裸 仓库
- InfoPath Resource Sites
- 自动驾驶论文解析(7)
- 2010-04-01 4over6tunnel配置——折腾了一天
- batchplot放到哪个文件夹_Batchplot使用技巧,转换CAD图纸格式并实现批量打印
- int f()与int f(void)的区别
- linux上samba+本地yum源最简单的配置
- 唐诗赏析html网页制作,【毕业论文】古诗词鉴赏网站的设计与实现.doc
- Java基础---整理1:JRE+进制+注释+关键字+标识符+变量
- 测试|模拟器Genymotion、Emulator、夜神配置选择
- python模拟登录qq邮箱爬取_python模拟登录qq邮箱
热门文章
- 2015 ACM Arabella Collegiate Programming Contest(F题)
- C语言中的有符号与无符号(挖坑)
- c语言零错误零警告,C语言 g警告:无符号表达式的比较0始终为false
- 谷歌学术+SCI-HUB一键下载SCI文献
- php上传文件失败的原因,PHP图片文件上传失败的原因
- 【数字图像处理】实验一 图像的平移,缩放和旋转(vs2017+opencv)
- AndroidPlayPlane战机小游戏
- 乱发短信的脉脉终于败诉了,网友:早就该判刑了
- 达人评测 i5 1135g7和i5 11300h的区别
- 适合学生写的请假管理系统