简体   繁体   English

DropDownList SelectedIndexChanged不触发(AutoPostBack =“ true”)

[英]DropDownList SelectedIndexChanged not firing (AutoPostBack=“true”)

I have a dropdownList on my webpage inside update panel. 我的网页上的更新面板中有一个dropdownList。 When I select a different value from the drop-down list, nothing happens which means that the "SelectedIndexChanged" event is not firing. 当我从下拉列表中选择一个不同的值时,什么也没有发生,这意味着“ SelectedIndexChanged”事件没有触发。

ASPX Code: ASPX代码:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
     <table class="table table-mv-vouchers" style="margin:0px;" cellspacing="0" cellpadding="0">
                        <caption class="mv-clearfix">                            
                         <asp:DropDownList ID="ddlShort" Width="150"  runat="server" AutoPostBack="True" ViewStateMode="Enabled"  EnableViewState="true"  OnSelectedIndexChanged="ddlShort_SelectedIndexChanged">
                            <asp:ListItem Text="By Estimate" Value="EstimateValue"></asp:ListItem>
                            <asp:ListItem Text="By Merchant" Value="MerchantName" Selected="True"></asp:ListItem>
                            <asp:ListItem Text="By Type" Value="MerchantCategory"></asp:ListItem>
                            <asp:ListItem Text="By Validity" Value="Validity"></asp:ListItem>                        
                        </asp:DropDownList>                                                          
                        </caption>
                        </table>
</ContentTemplate></asp:UpdatePanel>

Server Side Code: 服务器端代码:

protected void ddlShort_SelectedIndexChanged(object sender, EventArgs e)
{
    string ByShort = ddlShort.SelectedValue;
    if (ByShort != null)
    {
        DataSet dsAllMerchant = Main.Instance.serClient.GetMerchantList(null,true, ByShort, null,currentBaID,true);
        DataTable newdata = this.GenerateData(dsAllMerchant.Tables[0]);
        lvGiftVoucher.DataSource = newdata;
        lvGiftVoucher.DataBind();
    }
}

My problem was <caption class="mv-clearfix"> </caption> tag, I think this tag is not recognize. 我的问题是<caption class="mv-clearfix"> </caption>标记,我认为该标记无法识别。 After deleting this tag dropdownlist is firing. 删除此标签后,dropdownlist被触发。 Thanks all for your answering. 谢谢大家的回答。

I think you should add a trigger to your UpdatePanel, like that: 我认为您应该将触发器添加到UpdatePanel,如下所示:

<asp:updatepanel ...>
   <triggers>
       <asp:asyncpostbacktrigger controlid="DrpEmployeeType" eventname="SelectedIndexChanged" />
   </triggers>
</asp:updatepanel>

将UpdatePanel更新模式更改为始终

UpdateMode="Always"

Ensure that you have: 确保您具有:

  • a ScriptManager on your page 页面上的ScriptManager
  • an UpdatePanel which wraps the lvGiftVoucher markup 包装lvGiftVoucher标记的UpdatePanel
  • provided a unique Id to you update-panel 为您提供了一个唯一的ID更新面板
  • an AsyncPostbackTrigger for dropdown SelectedIndexChanged event 用于下拉SelectedIndexChanged事件的AsyncPostbackTrigger
  • set UpdateMode to Conditional UpdateMode设置为Conditional
  • AutoPostback = "True" for the dropdwonlist (you already did it) AutoPostback = "True"代表dropdwonlist(您已经做到了)

Dropdown markup (as is, just remove the updatepanel wrap) 下拉标记(照原样,只需删除updatepanel包装即可)

<table class="table table-mv-vouchers" style="margin:0px;" cellspacing="0" cellpadding="0">
<caption class="mv-clearfix">                            
 <asp:DropDownList ID="ddlShort" Width="150"  runat="server" AutoPostBack="True" ViewStateMode="Enabled"  EnableViewState="true"  OnSelectedIndexChanged="ddlShort_SelectedIndexChanged">
    <asp:ListItem Text="By Estimate" Value="EstimateValue"></asp:ListItem>
    <asp:ListItem Text="By Merchant" Value="MerchantName" Selected="True"></asp:ListItem>
    <asp:ListItem Text="By Type" Value="MerchantCategory"></asp:ListItem>
    <asp:ListItem Text="By Validity" Value="Validity"></asp:ListItem>                        
</asp:DropDownList>                                                          
</caption>
</table>

UpdatePanel mark-up UpdatePanel标记

<asp:UpdatePanel runat="server" id="up1" UpdateMode="Conditional" ChildrenAsTrigger="False">
    <Triggers>
        <asp:AsyncPostbackTrigger ControlId="ddlShort" EventName="SelectedIndexChanged" />
    </Triggers>
    <ContentTemplate>
        <!-- lvGiftVoucher markup here -->
    </ContentTemplate>
</asp:UpdatePanel>

我同意Sachu .....服务器端编码,在“ PageLoad事件”上..(!IsPostback)事件应在内部发生并调用“ Drop downList”

is your webpage created with master page? 您的网页是使用母版页创建的吗? If so then check that your form tag is in which page master page/webpage. 如果是这样,请检查您的表单标签在哪个页面母版页/网页中。 If it is in master page then simple emit that one and use form tag in webpage. 如果它在母版页中,则简单地发出那个并在网页中使用表单标签。

The same code is working fine in my PC.... 相同的代码在我的PC上工作正常

Edited, 编辑,

try this 尝试这个

add following code inside your Update panel 在“更新”面板中添加以下代码

<Triggers>
    <asp:PostBackTrigger ControlID="ddlshort" />
    <asp:AsyncPostBackTrigger ControlID="ddlshort" EventName="SelectedIndexChanged"  />
</Triggers>

hope this work.... 希望这项工作...

try the following: 尝试以下方法:
1. add a try-catch block and see if you are getting any exception. 1.添加一个try-catch块,看看是否有任何异常。
2. if your update panel UpdateMode is conditional , then you have to manually call Update() method or the panel will not update. 2.如果您的更新面板UpdateModeconditional ,则您必须手动调用Update()方法,否则面板将不会更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM