[英]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.