简体   繁体   中英

DropDownList SelectedIndexChanged not firing (AutoPostBack=“true”)

I have a dropdownList on my webpage inside update panel. When I select a different value from the drop-down list, nothing happens which means that the "SelectedIndexChanged" event is not firing.

ASPX Code:

<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. After deleting this tag dropdownlist is firing. Thanks all for your answering.

I think you should add a trigger to your UpdatePanel, like that:

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

将UpdatePanel更新模式更改为始终

UpdateMode="Always"

Ensure that you have:

  • a ScriptManager on your page
  • an UpdatePanel which wraps the lvGiftVoucher markup
  • provided a unique Id to you update-panel
  • an AsyncPostbackTrigger for dropdown SelectedIndexChanged event
  • set UpdateMode to Conditional
  • AutoPostback = "True" for the dropdwonlist (you already did it)

Dropdown markup (as is, just remove the updatepanel wrap)

<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

<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....

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.
2. if your update panel UpdateMode is conditional , then you have to manually call Update() method or the panel will not update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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