AJax技术

Ajax 学习总结

字号+ 作者:H5之家 来源:H5之家 2017-01-05 14:00 我要评论( )

http://blog.csdn.net/wzhibin/archive/2007/03/21/1536303.aspx

Ajax: A New Approach to Web Applications

更详尽的资料:

需要运行在

面向.NET开发人员的Ajax 技术平台策略

三、什么是我们所需要的

四、AnThem.Net应用

a)配置

b)控件应用

1)Add a Register directive to the top of your page:

<%@ Register TagPrefix="anthem" Namespace="Anthem" Assembly="Anthem" %>

2)Add an anthem:Button control to your page:

<anthem:Button runat="server" Text="Click Me!" />

3)Add an anthem:Label control to your page:

<anthem:Label runat="server" />

4)Add a handler for the button's Click event either by double-clicking on the button in the designer or by adding an OnClick attribute to the button's tag:

<anthem:Button runat="server" Text="Click Me!" OnClick="button_Click" />

5)Implement the handler in your code behind class or in a server-side script block in your page. Set the Text property like a normal Label control but make sure you set the UpdateAfterCallBack property to true or you won't see the change reflected on the page:

<script runat="server"> void button_Click(object sender, EventArgs e) { label.Text = DateTime.Now.ToString(); label.UpdateAfterCallBack = true; } </script> 其实1-4步我们都可以通过VS.NET设计器帮我们完成,我们需要做的可能就在在服务器端添加一句label.UpdateAfterCallBack = true;就可以了,操作十分方便。 另外如果你希望在服务器端代码执行完毕之后再向客户端抛一段脚本执行,原有的Page.RegisterStartupScript(key,script);方式已经不再有效,你需要采用如下的方式实现:Anthem.Manager.AddScriptForClientSideEval(script); [Anthem.Method] public int Add(int a, int b) { return a + b; }

2)Register the page with the Anthem manager when the page fires its Load event

void Page_Load() {

Anthem.Manager.Register(this);

}

3)Add three input controls and a button to trigger the call back to your page

<input size="3" value="1"> <input size="3" value="2"> <inputfont-size: 10pt;">DoAdd(); return false;" type="button">Add</input> <input size="6">

4)The button is invoking a client-side function called DoAdd. That function needs to be defined on the page so that it invokes the server-side Add method

<script language="javascript" type="text/javascript"> function DoAdd() {

Anthem_InvokePageMethod(

'Add',

[document.getElementById('a').value, document.getElementById('b').value], function(result) { document.getElementById('c').value = result.value; } ); } </script>

五、Ajax.Net Pro应用

a)配置

<configuration>

<system.web>

<httpHandlers>

<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>

</httpHandlers>

[...]

</system.web>

</configuration>

b)同步方式调用服务器端方法

[AjaxPro.AjaxMethod]

public int AddTow(int p_intNum1,int p_intNum2)

{

return p_intNum1 + p_intNum2;

}

private void Page_Load(object sender, System.EventArgs e)

{

AjaxPro.Utility.RegisterTypeForAjax(typeof(Class1));

}

3)在前台脚本中调用该方法:

<script>

function add() {

var intReturn =AjaxSample.Class1.AddTow(1,2).value;

alert(intReturn);

}

</script>

c)异步方式调用服务器端方法

异步调用方式只是在客户端脚本写法有不同:

<script>

function add() {

AjaxSample.Class1.AddTow(1,2,add_callback);

}

function add_callback(res){

alert(res.value);

}

</script>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Json学习笔记,json学习

    Json学习笔记,json学习

    2017-01-05 14:00

  • Ajax学习感悟

    Ajax学习感悟

    2017-01-05 13:03

  • 学习.net与ajax的详细案例总结

    学习.net与ajax的详细案例总结

    2017-01-05 13:02

  • ajax验证用户名是否可用

    ajax验证用户名是否可用

    2017-01-04 16:00

网友点评