首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >asp:我的用户控件中的下拉列表不会在被选中的索引更改后回发

asp:我的用户控件中的下拉列表不会在被选中的索引更改后回发
EN

Stack Overflow用户
提问于 2015-02-12 10:43:50
回答 2查看 1.3K关注 0票数 1

我无法在我的用户控件中获得asp:下拉列表以回发以更新天数。

用户控件:

代码语言:javascript
复制
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Profile.ascx.cs" Inherits="TestApp2.Views.Profile" %>


<asp:UpdatePanel ID="ProfileMainUpdatePanel" runat="server">
        <ContentTemplate>
            <div class="form-group profile-form">
                <asp:DropDownList runat="server" id="selYear" class="form-control profile-date right-align" OnSelectedIndexChanged="selYear_SelectedIndexChanged" />
                <asp:DropDownList runat="server" id="selMonth" class="form-control profile-date right-align" OnSelectedIndexChanged="selMonth_SelectedIndexChanged"  />
                <asp:DropDownList runat="server" id="selDay" class="form-control profile-date right-align"/>
                <asp:label runat="server" class="control-label right-align profile-form-label" for="selDay" Text="Date of Birth" ID="temp" />
            </div>
        </ContentTemplate>
</asp:UpdatePanel>

以及后面的代码

代码语言:javascript
复制
    public void fillDays()
    {
        selDay.Items.Clear();
        //getting numbner of days in selected month & year
        int noofdays = DateTime.DaysInMonth(Convert.ToInt32(selYear.SelectedValue), Convert.ToInt32(selMonth.SelectedValue));

        //Fill days
        for (int i = 1; i <= noofdays; i++)
        {
            selDay.Items.Add(i.ToString());
        }
        selDay.Items.FindByValue(System.DateTime.Now.Day.ToString()).Selected = true;// Set current date as selected

    }

    protected void selMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        temp.Text = "here";
        fillDays();
    }

    protected void selYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        temp.Text = "there";
        fillDays();
    }

它在页面加载上都可以很好地设置,但是这个回调位不会触发,甚至标签文本也不会改变。

我还试图通过将这些添加到inital设置中来处理它的客户端。

代码语言:javascript
复制
selYear.Attributes.Add("onchange", "fillDays();");
selMonth.Attributes.Add("onchange", "fillDays();");

客户端代码如下:

代码语言:javascript
复制
<script type="text/javascript">

function fillDays() {
    alert("yes");
}

也不会开火。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-12 10:45:14

您需要设置AutoPostBack="true"来获取SelectedIndexChanged事件,DropDownList的默认设置是false

代码语言:javascript
复制
<asp:DropDownList runat="server" id="selYear" AutoPostBack="true" class="form-control profile-date right-align" OnSelectedIndexChanged="selYear_SelectedIndexChanged"  />

AutoPostBack

获取或设置一个值,该值指示当用户更改列表选择MSDN时是否自动发生对服务器的回发。

票数 1
EN

Stack Overflow用户

发布于 2015-02-12 11:08:45

代码语言:javascript
复制
 try this in Update Panel. Hope its working...


  <asp:UpdatePanel ID="ProfileMainUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
    <ContentTemplate>
        <div class="form-group profile-form">
            <asp:DropDownList runat="server" id="selYear" class="form-control profile-date right-align" OnSelectedIndexChanged="selYear_SelectedIndexChanged" />
            <asp:DropDownList runat="server" id="selMonth" class="form-control profile-date right-align" OnSelectedIndexChanged="selMonth_SelectedIndexChanged"  />
            <asp:DropDownList runat="server" id="selDay" class="form-control profile-date right-align"/>
            <asp:label runat="server" class="control-label right-align profile-form-label" for="selDay" Text="Date of Birth" ID="temp" />
        </div>
    </ContentTemplate>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28475379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档