In the above article, I mentioned an application of the Page. IsPostBack attribute, which can be used to save
Information, I will introduce another use of it, that is, replacing the RS (Remote Scripting) technology in ASP.
I have already introduced the basic concepts and usage of RS in asp. The main advantage of RS is that it does not refresh
The current page communicates with the server. However, because java technology is used at the underlying layer
It still seems cumbersome. Next I will introduce how to use Page. IsPostBack to replace the RS technology in ASP +.
According to my habit, I like to use specific examples to explain the problem. So this time I will use a simple example to explain it.
Problem. In the following example, a Products. aspx program is used. It mainly has two Server-side controls (Server-side
Control). This is a new control programming method introduced in asp +. One is a drop-down box control-mudCategories,
The other is the list box control-mudProducts. This example shows that the content in the list box will follow the content in the drop-down box.
For the convenience of reproduction, I will use the database examples in SQL Server.
The Products. aspx code is as follows:
<% @ 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">
Product catalog:
<Asp: DropDownList id = "mudCategories" runat = "server" DataTextField = "CategoryName" DataValueField = "CategoryID" AutoPostBack = "true" OnSelectedIndexChanged = "displayProducts"/>
Product: <asp: ListBox id = "mudProducts" SelectionMode = "Multiple" DataValueField = "ProductID" DataTextField = "ProductName" runat = "server"/>
</Html>
We can see from the example program that the OnChange event in the drop-down box of the server control is used in combination with AutoPostBack and
The Page. IsPostBack attribute can easily and clearly implement the previously cumbersome RS Implementation Method in asp.
Well, I hope you will have some gains from the above example.