ASP.NET中DropDownList的自动回发 [英] AutoPostback for DropDownList in asp.net

查看:85
本文介绍了ASP.NET中DropDownList的自动回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为DropDownList设置AutoPostback = True时,则仅触发SelectedIndexChanged事件,否则不会触发...

When I set AutoPostback=True for DropDownList, then only the SelectedIndexChanged event is fired otherwise not...

即使AutoPostback = false ...,我也要触发事件.

I want to fire the event even when AutoPostback=false....

对此有什么解决方案吗?

Is there any solution for this...

 <asp:DropDownList ID="SlotDuration_DDL" runat="server" Style="color: #727272 !important; font-size: 24px; font-weight: 100;" CssClass="span2" OnSelectedIndexChanged="SlotDuration_DDL_SelectedIndexChanged">

      <asp:ListItem>10</asp:ListItem>
      <asp:ListItem>15</asp:ListItem>
      <asp:ListItem>20</asp:ListItem>
      <asp:ListItem>25</asp:ListItem>
      <asp:ListItem>30</asp:ListItem>
      <asp:ListItem>35</asp:ListItem>
      <asp:ListItem>40</asp:ListItem>
      <asp:ListItem>45</asp:ListItem>
      <asp:ListItem>50</asp:ListItem>
      <asp:ListItem>55</asp:ListItem>
      <asp:ListItem>60</asp:ListItem>
  </asp:DropDownList>

后面的代码

protected void SlotDuration_DDL_SelectedIndexChanged(object sender, EventArgs e)
{
   DateTime dt = DateTime.Parse(StartDate_TB.Text);
        int n = Int32.Parse(EventDuration_DDL.SelectedItem.ToString());
        for (int i = 0; i < n; i++)
        {
            Label NewLabel = new Label();
            NewLabel.ID = "Label" + i;
            var eventDate = dt.AddDays(i); //Calendar1.SelectedDate.Date.AddDays(i);
            NewLabel.Text = eventDate.ToLongDateString();

            CheckBox newcheck = new CheckBox();
            newcheck.ID = "CheckBox" + i;

            this.Labeldiv.Controls.Add(new LiteralControl("<span class='h1size'>"));
            this.Labeldiv.Controls.Add(NewLabel);
            this.Labeldiv.Controls.Add(new LiteralControl("</span>"));
            this.Labeldiv.Controls.Add(new LiteralControl("<div class='make-switch pull-right' data-on='info'>"));
            this.Labeldiv.Controls.Add(newcheck);
            this.Labeldiv.Controls.Add(new LiteralControl("</div>"));
            this.Labeldiv.Controls.Add(new LiteralControl("<br/>"));

        }
 }

即使将 AutoPostback 设置为false,也会触发

推荐答案

SelectedIndexChanged 事件.但是该页面不会立即回发.

SelectedIndexChanged event is fired even if you set AutoPostback to false. But the page does not postback immediately.

因此,如果用户更改DDL的选择,然后(可能在页面中做了其他事情之后)单击提交页面的按钮( postback ),则将调用此事件的处理程序

So If the user change the selection of the DDL and then (possibly after doing other things in the page) clicks in a button submiting the page (postback) The handler for this event will be called.

这篇关于ASP.NET中DropDownList的自动回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆