我的页面中有一个用户控件(位于包含 scriptmanager 标记的母版页中),其中包含两个下拉列表。ddl1(aka CatList)的值决定了 ddl2(aka CatList2)的内容。过去,每次更改 ddl1 时,我都会使用完整的回发来完成此操作,但由于各种原因,在这种情况下,我更希望它进行部分回发,但是,我似乎无法让部分回发工作. 我的代码,就目前而言,如下所示。
<%@ Control Language="VB" AutoEventWireup="true" Inherits="System.Web.UI.UserControl" ClassName="KnownIssuesCode" %>
<%@ Import namespace="system.data" %>
<%@ Import namespace="system.data.SqlClient" %>
<script runat="server">
Protected Dim ThePage as string
Sub Page_Load()
If Not Page.IsPostBack Then
Dim myReader4 As IDataReader = CType(GetProduct.Select(DataSourceSelectArguments.Empty), IDataReader)
CatList.Items.Clear()
CatList.DataValueField = "ProductID"
CatList.DataTextField = "ProductName"
CatList.DataSource=myReader4
CatList.DataBind()
CatList.SelectedValue = "0"
myReader4.close
If not isNothing(session("ProductID")) then
CatList.SelectedValue = session("ProductID")
ProductID.Text = session("ProductID")
Else
ProductID.Text = 0
End if
Dim myReader2 As IDataReader = CType(GetModule.Select(DataSourceSelectArguments.Empty), IDataReader)
CatList2.Items.Clear()
CatList2.DataValueField = "ModuleID"
CatList2.DataTextField = "ModuleName"
CatList2.DataSource=myReader2
CatList2.DataBind()
CatList2.SelectedValue = "0"
myReader2.close
End If
End Sub
Sub CatListIndex_Changed(sender As Object, e As EventArgs)
ProductID.Text = CatList.SelectedValue
Dim myReader2 As IDataReader = CType(GetModule.Select(DataSourceSelectArguments.Empty), IDataReader)
CatList2.Items.Clear()
CatList2.DataValueField = "ModuleID"
CatList2.DataTextField = "ModuleName"
CatList2.DataSource=myReader2
CatList2.DataBind()
CatList2.SelectedValue = "0"
myReader2.close
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
session("ProductID") = CatList.SelectedValue
session("ModuleID") = CatList2.SelectedValue
response.redirect("known-issues.aspx")
End Sub
</script>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="False" runat="server">
<ContentTemplate>
<div class="block-holder">
<div class="block-frame">
<div class="form-block">
<h1>KNOWN ISSUES</h1>
<div class="add-search-form">
<fieldset>
<div class="container">
<div class="row">
<asp:dropdownlist title="PRODUCT" id="CatList" OnSelectedIndexChanged="CatListIndex_Changed" AutoPostback="True" CssClass="size-3" runat="server" />
</div>
<div class="row">
<asp:dropdownlist id="CatList2" title="MODULE" CssClass="standard" runat="server" />
</div>
<asp:Label ID="ProductID" runat="server" visible="false"></asp:Label>
</div>
<asp:Button ID="Button1" runat="server" Text="Search" />
</fieldset>
</div>
<span class="add-desc">FIND workarounds AND solutions</span>
</div>
</div>
</div>
<asp:SqlDataSource ID="GetModule" runat="server"
ConnectionString="<%$ ConnectionStrings:XXX %>"
SelectCommand="SELECT ModuleID, ModuleName, ModuleSeq from Module where ModuleDeleted = 0 and (ProductID=@ProductID or ProductID=0) order by ModuleName"
DataSourceMode="DataReader">
<SelectParameters>
<asp:ControlParameter ControlID="ProductID" Name="ProductID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CatList" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="GetProduct" runat="server"
ConnectionString="<%$ ConnectionStrings:XXX %>"
SelectCommand="SELECT ProductID, ProductName, ProductSeq from Product order by ProductSeq"
DataSourceMode="DataReader">
</asp:SqlDataSource>
eta:目前,不是进行部分回发,而是进行完整回发。