ASP.NET AJAX入门系列(9):使用ScriptManager控件

运行后效果如下:

ASP.NET AJAX入门系列(9):使用ScriptManager控件

当然了也可以在运行时动态的在Services中加入ServiceReference,下面看一个运行时动态加入ServiceReference的例子:

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3"  %>

< 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.NET AJAX入门系列(9):使用ScriptManager控件

 

六.Scripts属性

关于Scripts属性到后面具体再说吧,最主要的属性有Path指定脚本的路径,ScriptMode指定客户端脚本的模式,它会覆盖ScriptManager中的ScriptMode属性,还有一个属性是IgnoreScriptPath,指定是否忽略掉ScriptManager中的ScriptPath属性。

关于ScriptManager控件就学习到这里了,至于AuthenticationService属性和ProfileService属性都很简单。

示例代码下载:http://files.cnblogs.com/Terrylee/ASPNETAJAXScriptManagerDemo.rar

你可能感兴趣的:(asp.net)