我无法在我的用户控件中获得asp:下拉列表以回发以更新天数。
用户控件:
<%@ 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>以及后面的代码
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设置中来处理它的客户端。
selYear.Attributes.Add("onchange", "fillDays();");
selMonth.Attributes.Add("onchange", "fillDays();");客户端代码如下:
<script type="text/javascript">
function fillDays() {
alert("yes");
}
也不会开火。
发布于 2015-02-12 10:45:14
您需要设置AutoPostBack="true"来获取SelectedIndexChanged事件,DropDownList的默认设置是false。
<asp:DropDownList runat="server" id="selYear" AutoPostBack="true" class="form-control profile-date right-align" OnSelectedIndexChanged="selYear_SelectedIndexChanged" />AutoPostBack
获取或设置一个值,该值指示当用户更改列表选择MSDN时是否自动发生对服务器的回发。
发布于 2015-02-12 11:08:45
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>
https://stackoverflow.com/questions/28475379
复制相似问题