射击SelectedIndexChanged事件,但列表框的AutoPostBack属性是假的 - ASP.NET [英] Firing SelectedIndexChanged event , but the listbox's autopostback property is false - ASP.NET

查看:121
本文介绍了射击SelectedIndexChanged事件,但列表框的AutoPostBack属性是假的 - ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是更新面板。在本次更新面板上,有一个列表框控件。其实我AutoPostBack属性设置为code假后面。但仍执行SelectedIndexChanged事件,如果选定的索引被改变。

I am using an update panel . In this update panel, there is a listbox control. I actually set autopostback property to false in code behind. But still it executing SelectedIndexChanged event if the selected index is changed.

为什么出现这种情况?

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>

                                            <asp:MultiView ID="mvForms" runat="server" ActiveViewIndex="1">
                                                <asp:View ID="View1" runat="server">
                                                     <asp:Panel ID="Panel5" runat="server" GroupingText="Available Evaluation Forms" meta:resourcekey="rsKey_panel5"
                                                     Width="100%">
                                                         <asp:ListBox ID="lbAvailableForms" runat="server" AutoPostBack="true"
                                                             style="height: 125px; width: 95%;" 
                                                             onselectedindexchanged="lbAvailableForms_SelectedIndexChanged"></asp:ListBox>
                                                      </asp:Panel>
                                                </asp:View>
                                                <asp:View ID="View2" runat="server">
                                                     <asp:Panel ID="Panel11" runat="server" GroupingText="Available Evaluation Forms" meta:resourcekey="rsKey_panel11"      Width="100%">
                                                        <div  style="height: 125px; width: 95%; text-align:center;">
                                                            <br />
                                                            <br />
                                                            <asp:Label ID="lblAllSelected" runat="server" Text="All Selected" meta:resourcekey="rsKey_lblAllSelected"></asp:Label></div>
                                                    </asp:Panel>
                                                </asp:View>
                                            </asp:MultiView>
                               </ContentTemplate>
                             <Triggers>      
                           <asp:AsyncPostBackTrigger ControlID="RLCompareParameter" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>          
                            <asp:AsyncPostBackTrigger ControlID="cbAllForms" EventName="CheckedChanged"></asp:AsyncPostBackTrigger>
                        </Triggers>
                      </asp:UpdatePanel>            

该列表框的名字是lbAvailableForms。在调试时我检查该列表框控件的AutoPostBack属性,然后我发现,财产是假的。它显得那么陌生又如何SelectedIndexChanged事件触发

The listbox name is lbAvailableForms. While debugging i checked the autopostback property of this list box control, then i found that the property is false. Its looking so strange then how the selectedindexchanged event firing

下面cbAllForm是一个复选框控制和RLCompareParameteris一个radilo列表。

Here cbAllForm is a check box control and RLCompareParameteris a radilo list.

有时候,我需要得到自动回传属性为true。所以最初我这个属性设置为true。下RLCompareParameter_SelectedIndexChanged事件,我设置lbAvailableForms.Autopostback = FALSE。但仍属性设置为false后,列表框中选择射击事件indexchanged

Sometimes i need to get auto postback property is true. So initially i set this property to true. under RLCompareParameter_SelectedIndexChanged event , i set lbAvailableForms.Autopostback=false. But still after setting the property to false ,the listbox firing selected indexchanged event

推荐答案

这可能是来不及修改<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback.aspx\"相对=nofollow>的AutoPostBack 在你的事件属性处理阶段:的的UpdatePanel 可能已经注册了自己的触发器。

It might be too late to change the AutoPostBack property in your event handling phase: the UpdatePanel may already have registered its triggers.

我想通过禁用的AutoPostBack 的ViewState (它可以记住的AutoPostBack

I would start by disabling AutoPostBack and ViewState (which remembers AutoPostBack) on the list box:

<asp:ListBox ID="lbAvailableForms" runat="server"
    AutoPostBack="False" EnableViewState="False"
    Style="height: 125px; width: 95%;"
    OnSelectedIndexChanged="lbAvailableForms_SelectedIndexChanged">
</asp:ListBox>

再介绍一个私有成员来跟踪我们想要做的,设置在事件处理程序的成员:

Then introduce a private member to keep track of what we want to do and set that member in the event handler:

private bool _disableAutoPostBack = false;

protected void RLCompareParameter_SelectedIndexChanged(object sender, EventArgs e)
{
    _disableAutoPostBack = true;
}

然后在 preRender 阶段使用它算账:

protected void Page_PreRender(object sender, EventArgs e)
{
    lbAvailableForms.AutoPostBack = !_disableAutoPostBack;
}

然后希望工程,因为它是,所以我们没有动态注册的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.asyncpostbacktrigger.aspx\"相对=nofollow> AsyncPostBackTrigger 上的的ListBox ,这将是混乱的。

这篇关于射击SelectedIndexChanged事件,但列表框的AutoPostBack属性是假的 - ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆