当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework

ASP.NET
asp.net 转换人民币大小金额
编写的vs2005水晶报表程序在vs2008下正常使用的一些实现方法
asp.net下获取浏览器类型的实现代码
asp.net coolite 删除时弹出确定按钮
asp.net Forms身份验证和基于角色的权限访问
asp.net 用继承方法实现页面判断session
asp.net DataGrid 中文字符排序的实现代码
asp.net 利用IIS的404错误将文件重写成目录的简单方法
Aspx/Asp.net 防注入程序 V1.0
C# 数组查找与排序实现代码
ASP.NET通过使页面动态加载不同CSS实现多界面
LINQ学习笔记:XDocument文档与XML声明
ASP.NET教程:如何动态写入服务器端控件
XML+XSLT+CSS+JQuery+WebService组建Asp.Net网站
ASP.NET效率陷阱之:Attributes
.NET vs J2EE:面对SOA的荒谬与误解
ASP.NET学习篇(1):开篇
ASP.NET学习篇(2):安装与配置
ASP.NET学习篇(3):几个简单的ASP.ENT的例子
ASP.NET学习篇(4):服务器端的控件

ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 35 ::
收藏到网摘: n/a

导 读: 
通过一个例子说明了如何利用Page.IsPostBack属性,来取代ASP中的RS(Remote Scripting)技术,以实现在不刷新当前页面的情况下和服务器端进行通信. 
--------------------------------------------------------------------------------
  Page.IsPostBack属性的一个应用,可以用来保存用户输入的
信息,下面我将介绍它的另外一个用处,那就是取代ASP中的RS(Remote Scripting)技术。
至于RS的基本概念和用法我已经在asp版里面有很多介绍了,它主要的优势就是在不刷新
当前页面的情况下和服务器端进行通信。但是由于它的底层是使用了java技术,所以它用
起来还是显得较为烦琐,下面我就将介绍在ASP+中如何利用Page.IsPostBack来取代RS技术。
    按照我的习惯是喜欢用具体的例子来解释问题,所以这次还是使用一个简单的实例来说明
问题。下面这个例子中,将使用一个Products.aspx程序,它主要有两个服务器端控件(Server-side
control),这是asp+里面引入的新的控件编程方式,一个是一个下拉框控件--'mudCategories',
另外一个是列表框控件--'mudProducts'。这个例子将演示,列表框中的内容将跟随下拉框中内容
的改变而改变,为了大家重现的方便,我将使用SQL Server中自带的数据库例子来实现。

Products.aspx代码如下:

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.ADO"%>
<script language="VB" runat="server">
Sub Page_Load (SourceObj as Object, EveArg as EventArgs)

If Not Page.IsPostBack Then    
    Dim mudCommand As ADODataSetCommand
    Dim mudConnection As ADOConnection
    Dim dSet As New DataSet
    Dim strSQL as String
    Dim connStr as String
            
    strSQL = "SELECT CategoryID, CategoryName From Categories"
    connStr = "Provider = SQLOLEDB; Data Source=test; Initial Catalog=Northwind; User         ID=sa; password=;"

    mudConnection = New ADOConnection(connStr)        
    mudCommand = New ADODataSetCommand(strSQL,  mudConnection)        
    mudCommand.FillDataSet(dSet, "Categories")            
    mudCategories.DataSource = dSet.Tables("Categories").DefaultView
    mudCategories.DataBind()
End If
End Sub

Sub displayProducts (Source as Object, EveArg as EventArgs)

    Dim mudCommand As ADODataSetCommand
    Dim mudConnection As ADOConnection
    Dim dSet As New DataSet
    Dim strSQL as String
    Dim connStr as String
    
    connStr = "Provider = SQLOLEDB; Data Source=test; Initial Catalog=Northwind; User     ID=sa; password=;"
        
    strSQL = "Select ProductID, ProductName From Products"
    strSQL = strSQL & " WHERE CategoryID = " & mudCategories.SelectedItem.Value 
        
    mudConnection = New ADOConnection(connStr)    
    mudCommand = New ADODataSetCommand(strSQL,  mudConnection)        
    mudCommand.FillDataSet(dSet, "Products")            
    mudProducts.DataSource = dSet.Tables("Products").DefaultView
    mudProducts.DataBind()
End Sub
    
</script>
<html>
<form name="mudForm" runat="server">
    
产品目录: 
<asp:DropDow