上一篇:ASP.NET如何在窗体和窗体之间传送数据 >>
ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework
通过一个例子说明了如何利用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:DropDownList id="mudCategories" runat="server" DataTextField="CategoryName" DataValueField="CategoryID" AutoPostBack="true" OnSelectedIndexChanged="displayProducts"/>
产品: <asp:ListBox id="mudProducts" SelectionMode="Multiple" DataValueField="ProductID" DataTextField="ProductName" runat="server" />
</html>
从例子程序可以看到,其中显然是使用了服务器端控件的下拉框OnChange事件配合AutoPostBack和
Page.IsPostBack属性就可以很简单和清晰的实现了以前在asp中烦琐的RS实现方法。
相关文章:
- · ASP.NET保持用户状态的九种选择(上)
- · ASP.NET的用户控件
- · ASP.NET对IIS中的虚拟目录进行操作
- · ASP.NET读取POP3邮件的操作
- · 基于ASP.NET实现全球化
- · ASP.NET中使用IFRAME建立类Modal窗口
- · 解决ASP.NET创建的线程的用户改变引发的拒绝访问错误
- · 在ASP.NET中实现弹出日历
- · ASP.NET中共用代码
- · 实现一个Asp.net自定义Back控件
- · ASP.net下的前台日历控件源代码
- · Asp.net中对象使用的实例
- · ASP.NET 链接数据库基础
- · 在ASP.NET下使用水晶报表一
- · Asp.net中对象使用的实例
- · Asp.Net中使用水晶报表(下)
- · Asp.Net中使用水晶报表(中)
- · Asp.Net中使用水晶报表(上)
- · 在vb.net中使用webbrowser控件和mshtml以及流操作体会(vb.net内嵌IE,拆取 Web 页)
- · 在ASP.NET 中实现单点登录
- · asp.net 关于form认证的一般设置
- · Asp.net中对象使用的实例
- · 解读ASP.NET 2.0 Internals
- · oracle9i连接asp.net方法及注意点
- · Asp.Net中使用水晶报表(下)
- · Asp.Net中使用水晶报表(中)
- · Asp.Net中使用水晶报表(上)
- · ASP.NET导出数据到Excel
- · ASP.net下的前台日历控件源代码(不刷新页面)
- · 用ASP.NETt实现简单的文字水印
- · 在ASP.Net中两种利用CSS实现多界面的方法.
- · 用Asp.net实现简单的文字水印
- · Asp.net 实现验证码功能的Web控件
- · ASP.NET结合存储过程写的通用搜索分页程序
- · ASP.net随机数应用实例
- · asp.NET特写
- · ASP.NET中Cookie编程简明参考
- · ASP.NET中Datagrid常见错误
