首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阻止ControlParameter AutoPostBack触发ObjectDataSource选择方法

阻止ControlParameter AutoPostBack触发ObjectDataSource选择方法
EN

Stack Overflow用户
提问于 2019-03-19 23:19:39
回答 2查看 223关注 0票数 1

我已经创建了一个简单的ASP Gridview,它使用一个ObjectDataSource从我的数据库中获取数据并在GridView中显示它。ObjectDataSource如下所示:

代码语言:javascript
复制
<asp:ObjectDataSource 
    ID="ObjectDataSourceTest" 
    runat="server"
    SelectMethod="GetTestData" 
    TypeName="DataManager" 
    <SelectParameters>
        <asp:Parameter Name="sortExpression" Type="String" />
        <asp:ControlParameter ControlID="DropDownListXY" Name="xyFilter" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

ControlParameter是用于过滤我的GridViewDropDownList。它被放在一个<asp:Panel>中,看起来像这样:

代码语言:javascript
复制
<div class="grid-100">
    <asp:DropDownList ID="DropDownListXY" OnSelectedIndexChanged="DropDownListXY_SelectedIndexChanged" DataSourceID="ObjectDataSourceApplikationTyp" runat="server" DataValueField="test_guid" DataTextField="test" AppendDataBoundItems="true" AutoPostBack="true">
    <asp:ListItem Text="-- all --" Value=""></asp:ListItem>
    </asp:DropDownList>
</div>

我的问题是,每当我从DropDownList中选择某项内容时,它都会触发SelectMethod。我试着在我的DropDownList上关闭AutoPostBack,但是PostBack对其他功能很重要,所以我不能把它留在AutoPostBack="false"上,它必须一直在True上。

我的问题是:我如何防止这种情况发生。我想把AutoPostBack保留在DropDownList上。但是我的SelectMethod不应该同时触发。我希望能够控制何时使用搜索按钮过滤我的数据。

EN

回答 2

Stack Overflow用户

发布于 2019-03-26 23:33:30

你可以使用更新面板来防止selectIndex上的自动回发我遇到了sam问题,最近我想创建一个级联下拉菜单,我不想让页面在选定的索引更改时重新刷新。如果你想知道更多,这个教程有你的问题https://www.aspsnippets.com/Articles/Cascading-DropDownList-for-CountryStateCity-in-ASPNet.aspx的解决方案。

否则,您的代码应该如下所示。

代码语言:javascript
复制
    <div class="grid-100">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
        <ContentTemplate>
        <asp:DropDownList ID="DropDownListXY" OnSelectedIndexChanged="DropDownListXY_SelectedIndexChanged" DataSourceID="ObjectDataSourceApplikationTyp" runat="server" DataValueField="test_guid" DataTextField="test" AppendDataBoundItems="true" AutoPostBack="true">
        <asp:ListItem Text="-- all --" Value=""></asp:ListItem>
        </asp:DropDownList>
        </ContentTemplate>
         <Triggers>
             <asp:AsyncPostbackTrigger ControlID="DropDownListXY" EventName="SelectedIndexChanged" />
              <asp:PostBackTrigger ControlID="btnConfirmPurchases" />
          </Triggers>
         </asp:UpdatePanel>

    </div>

希望这能有所帮助。:)

票数 1
EN

Stack Overflow用户

发布于 2019-04-01 17:18:23

第一个方法: true我已经使用了这个方法它是有效的,将这个添加到您的dropdown onchange="javascript:setTimeout('__doPostBack(\'DropDownListXY\',\'\')',0)",并确保设置为

代码语言:javascript
复制
<div class="grid-100">
    <asp:DropDownList ID="DropDownListXY" OnSelectedIndexChanged="DropDownListXY_SelectedIndexChanged" DataSourceID="ObjectDataSourceApplikationTyp" runat="server" DataValueField="test_guid" DataTextField="test" AppendDataBoundItems="true" onchange="javascript:setTimeout('__doPostBack(\'DropDownListXY\',\'\')', 0)"  AutoPostBack="true">
    <asp:ListItem Text="-- all --" Value=""></asp:ListItem>
    </asp:DropDownList>
</div>

的第二个方法是将Dropdownlist放在UpdatePanel中,并在触发器中处理它的回发

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55244419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档