我的页面中有一个用户控件(位于包含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: 目前,它没有进行部分回发,而是进行完整的回发。
答案 0 :(得分:0)
删除ChildrenAsTriggers="False"
,ChildrenAsTriggers =“False”会导致UpdatePanel在所选触发器上回发。您可以在此处找到更多信息ChildrenAsTriggers
答案 1 :(得分:0)
替换:
Sub CatListIndex_Changed(sender As Object, e As EventArgs)
使用
Protected Sub CatListIndex_Changed(sender As Object, e As EventArgs) Handles CatList.SelectedIndexChanged
答案 2 :(得分:0)
问题原来是一个安全问题,而不是代码问题 - 我在不同的网站上测试了我的代码,它按预期工作。
在对安全设置进行了一些处理后,结果证明是我设置的通配符过滤的问题,以防止在没有登录的情况下访问非.net页面。取消关闭解决了ajax问题,至少对于这个网站来说,过滤可能有点过头了。