![](/img/trans.png)
[英]Selectedindexchanged for DDL is not firing (AutoPostBack = “true”)
[英]DropDownList SelectedIndexChanged not firing (AutoPostBack=“true”)
我的網頁上的更新面板中有一個dropdownList。 當我從下拉列表中選擇一個不同的值時,什么也沒有發生,這意味着“ SelectedIndexChanged”事件沒有觸發。
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>
服務器端代碼:
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();
}
}
我的問題是<caption class="mv-clearfix"> </caption>
標記,我認為該標記無法識別。 刪除此標簽后,dropdownlist被觸發。 謝謝大家的回答。
我認為您應該將觸發器添加到UpdatePanel,如下所示:
<asp:updatepanel ...>
<triggers>
<asp:asyncpostbacktrigger controlid="DrpEmployeeType" eventname="SelectedIndexChanged" />
</triggers>
</asp:updatepanel>
將UpdatePanel更新模式更改為始終
UpdateMode="Always"
確保您具有:
ScriptManager
lvGiftVoucher
標記的UpdatePanel
SelectedIndexChanged
事件的AsyncPostbackTrigger
UpdateMode
設置為Conditional
AutoPostback = "True"
代表dropdwonlist(您已經做到了) 下拉標記(照原樣,只需刪除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標記
<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”
您的網頁是使用母版頁創建的嗎? 如果是這樣,請檢查您的表單標簽在哪個頁面母版頁/網頁中。 如果它在母版頁中,則簡單地發出那個並在網頁中使用表單標簽。
相同的代碼在我的PC上工作正常 。
編輯,
嘗試這個
在“更新”面板中添加以下代碼
<Triggers>
<asp:PostBackTrigger ControlID="ddlshort" />
<asp:AsyncPostBackTrigger ControlID="ddlshort" EventName="SelectedIndexChanged" />
</Triggers>
希望這項工作...
嘗試以下方法:
1.添加一個try-catch
塊,看看是否有任何異常。
2.如果您的更新面板UpdateMode
是conditional
,則您必須手動調用Update()
方法,否則面板將不會更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.