Ajax之ASP.NET初级练习

779 篇文章 0 订阅
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
Ajax不能不说是一种很好的技术。刚下了一个Ajax.NET,来试试。 

从http://Ajax.NET/下载一个压缩包,解开过后有一个txt的quick usage guide和一个DOC的Ajax .NET Wrapper usage guide以及一个DLL。 

嗯,看看TXT的先。了解到Ajax开发的大概步骤: 

一、项目中建立一个引用,把Ajax.dll引用进来。 

二、修改web.config文件,加入 

<httpHandlers>  



          <add verb="POST,GET" path="Ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />  



</httpHandlers>  



三、在页面的page_load事件中添加如下代码:  



Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1));  



到这儿,页面就可以使用Ajax了。  




  


可以在后台代码中写一个函数,在客户端进行调用。比如:  



[Ajax.AjaxMethod()]  



public int ServerSideAdd(int firstNumber, int secondNumber)  



{  



       return firstNumber + secondNumber;  



}  



这儿[Ajax.AjaxMethod()]这句是一定要加的。不然在客户端没有办法使用。  



这样,在客户端就可以直接使用这个ServerSideAdd方法了。比如: 

function add2()  



 var re=WebForm1.ServerSideAdd(Form1.first.value,Form1.second.value )  

Form1.result.value =re.value;  




  


大家可以看到在JS中,这个服务端的方法前还跟了一个WebForm1,这是页面对应的类名。 

TXT文件中的例子只是让大家初步了解一下Ajax的一些作用,当然还有更强大的啦。作为客户端使用的方法,返回值不只可以是普通的如int、string这样的类型,还可以返回如DataSet和class这样的复杂类型,这也为客户端的“强javascript”提供了可能,让开发人员在界面上就可以进行“面向对象”的开发。 

同时,Ajax中的无刷新也是它的亮点之一。有名的组件ComponentArt新出的3。0产品,就有Call-back组件,大家有兴趣的话可以试试。 


  


当然微软也有Ajax产品:Atlas 

详细的情况可以参考: 

ASP.NET "Atlas" Preview Documentation 
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
命名变量,变量计算等(WindowsFormsApplication1): using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox1.Text="hello"; string teststring="hello, world!"; //定义变量 textBox1.Text = teststring; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { int testint1 = 1000; //定义变量 int testint2 = 60; testint2 += 60; testint1 /= 2; textBox1.Text = Convert.ToString(testint1 + testint2); //变量相加 textBox2.Text = Convert.ToString(testint1 % testint2); //变量取余数 textBox3.Text = Convert.ToString( testint2); //取最终变量数 textBox4.Text = Convert.ToString(testint1); //取最终变量数 textBox5.Text = Convert.ToString(--testint1); //取自减一 textBox6.Text = Convert.ToString(++testint1); //取自加以 textBox7.Text = Convert.ToString(testint1--); //取自减一 textBox8.Text = Convert.ToString(testint1); //取自减一 textBox9.Text = "\"hello, \n world!\""; //换行符和转移符 textBox10.Text = testint1 > testint2 ? "大于" : "不大于"; // > 的选择 textBox11.Text = testint1 == testint2 ? "相等" : "不相等"; // == 的选择 textBox12.Text = testint1 != testint2 ? "不相等" : "相等"; // != 的选择 Boolean testboolean = true; label1.Text = Convert.ToString(testboolean); label2.Text = Convert.ToString(!testboolean); label3.Text = Convert.ToString(6 == 3 & 3 > 6); // 需要两个都满足是true,否则false label4.Text = Convert.ToString(6 != 3 & 3 6); // 需要两个都满足或都不满足是false,否则true textBox13.Text = Convert.ToString(10 <> 3); //二进制的计算 } private void textBox6_TextChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void textBox13_TextChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { int testint1 = 1; int testsum = 0; while (testint1 60) //if语句 { textBox15.Text = "大于60"; } else if (testint > 80) { textBox15.Text = "大于80"; } else if (testint > 200) { textBox15.Text = "小于200"; } textBox16.Text = "好的"; goto hello; //goto语句 hello: textBox16.Text = "hello"; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值