在更新面板中未触发dropDownList的SelectedIndexChanged事件

时间:2016-09-22 05:48:28

标签: c# asp.net updatepanel

在更新面板中未触发dropDownList的SelectedIndexChanged事件,并且还设置了AutoPostBack =" true"。

以下是我的设计代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
<asp:DropDownList ID="ddl_TypeofCampaign" runat="server"  CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddl_TypeofCampaign_SelectedIndexChanged" AppendDataBoundItems="true" ViewStateMode="Enabled" EnableViewState="true" >
<asp:ListItem Text="Select" Value="0"></asp:ListItem>
<asp:ListItem Text="Email" Value="Email"></asp:ListItem>
<asp:ListItem Text="SMS" Value="SMS"></asp:ListItem>
<asp:ListItem Text="Voice SMS" Value="Voice SMS"></asp:ListItem>
</asp:DropDownList>

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"
DisplayAfter="1">
<ProgressTemplate>
<div id="IMGDIV" runat="server" align="center" style="visibility: visible; vertical-align: middle; position: absolute; background-color: #fafbf6"
valign="middle">
 <asp:Image ID="Image001" runat="server" ImageUrl="~/assets/img/ajax-loader.gif" />
 </div>
 </ProgressTemplate>
 </asp:UpdateProgress>

   </ContentTemplate>
</asp:UpdatePanel>

代码背后:

protected void ddl_TypeofCampaign_SelectedIndexChanged(object sender, EventArgs e)
{
    Thread.Sleep(2000);
    FillTemplates();
    btn_Preview.Visible = false;

}

我的页面加载代码。

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        FillGrid();
        FillTypeofSourcing();
        FillCampaignNames();
        FillTemplates();

    }
}

填写模板方法,我将根据选择获取模板名称。

 protected void FillTemplates()
{
    if (ddl_TypeofCampaign.SelectedItem.ToString() != "Select")
    {
        bo.Para1 = ddl_TypeofCampaign.SelectedItem.ToString();
        bo.Para2 = "Stage1";//StageValue in TemplateMasterInfo Table
        DataTable dt = bl.Get_Templates(bo);
        ddl_TypeofTemplateName.DataSource = dt;
        ddl_TypeofTemplateName.DataTextField = "TemplateName";
        ddl_TypeofTemplateName.DataValueField = "TemplateId";
        ddl_TypeofTemplateName.Items.Clear();
        ddl_TypeofTemplateName.Items.Add(new ListItem("Select", "0"));
        ddl_TypeofTemplateName.DataBind();
    }
    else
    {
        ddl_TypeofTemplateName.Items.Clear();
        ddl_TypeofTemplateName.Items.Add(new ListItem("Select", "0"));
        ddl_TypeofTemplateName.DataBind();
    }
}

2 个答案:

答案 0 :(得分:0)

尝试将Trigger添加到更新面板,如下所示

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

更新

       <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <Triggers> //this is missing in your code posted
     <asp:AsyncPostBackTrigger ControlID="ddl_TypeofCampaign" EventName="SelectedIndexChanged" /> 
   </Triggers> 
     <ContentTemplate>mydropcode </ContentTemplate> </asp:UpdatePanel>

答案 1 :(得分:0)

在页面标记中,我提到 viewStateEncryptionMode =&#34;从不&#34; ,我正在使用Visual Studio 2013.以下是我的页面标记详细信息。

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ViewCandidate.aspx.cs" Inherits="ViewCandidate" validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never" %>