0

我的页面中有一个用户控件(位于包含 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:目前,不是进行部分回发,而是进行完整回发。

4

3 回答 3

0

代替:

Sub CatListIndex_Changed(sender As Object, e As EventArgs) 

Protected Sub CatListIndex_Changed(sender As Object, e As EventArgs) Handles CatList.SelectedIndexChanged
于 2012-10-23T10:41:13.113 回答
0

问题被证明是安全问题,而不是代码问题 - 我已经在不同的网站上测试了我的代码,它按预期工作。

在对安全设置进行了一些处理之后,事实证明这是我设置的通配符过滤问题,以防止在未登录的情况下访问非 .net 页面。取消它解决了 ajax 问题,并且,至少对于这个站点,过滤可能是多余的。

于 2012-10-23T14:35:57.337 回答
0

Remove ChildrenAsTriggers="False",ChildrenAsTriggers="False" 会导致 UpdatePanel 在选定的触发器上回发。您可以在此处找到更多信息ChildrenAsTriggers

于 2012-10-23T10:35:44.913 回答