1

我有两个带有日历扩展器的文本框控件和一个下拉列表,如下所示。

<asp:TextBox ID="txtStartDate" runat="server" ReadOnly="True"></asp:TextBox>

<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="txtStartDate" 
    runat="server" Format="yyyy-MM-dd" />

<asp:TextBox ID="txtEndDate" runat="server" ReadOnly="True" 
             ontextchanged="txtEndDate_TextChanged">
</asp:TextBox>

<asp:CalendarExtender ID="txtEndDate_CalendarExtender" runat="server" 
                       Enabled="True" TargetControlID="txtEndDate" Format="yyyy-MM-dd">
</asp:CalendarExtender>

<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

我想要做的是当用户选择一个日期时,txtEndDate我想调用一个函数来加载数据DropDownList1,即 DataBind DropDownList1

当我将AutoPostBack属性设置txtEndDate 为 True 并在事件上调用方法时txtEndDate_TextChanged不会被触发。

我哪里错了谁能帮忙。我只想DropDownList1在用户选择日期时加载txtEndDate。我需要做什么。

这是我在我的aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String DB = "";
            String AccountID = "";
            if (Session["login"] != null && Session["db"] != null)
            {
                AccountID = Session["login"].ToString();
                DB = Session["db"].ToString();

                Label4.Text = AccountID;
            }
            else
            {
                Response.Redirect("log.aspx");
            }
        }
    }
    protected void txtEndDate_TextChanged(object sender, EventArgs e)
    {
       String databs = Session["db"].ToString();
       Response.Write(databs);
        ddlist1_crtno a = new ddlist1_crtno();
        a.filldropdown1(this.DropDownList1, databs);
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        // LOG OUT***********////////////
        Session.Abandon();
        Response.Redirect("log.aspx");  
    }
}

我在 ButtonClick 事件上放置了相同的事件,一切正常。

4

1 回答 1

1

尝试ReadOnly="true"TextBox控件中删除。这可能会解决您的问题。

TextBox控件存在问题,ReadOnly="true"即每当 PostBack 发生时文本框的值都会丢失,这就是事件未触发的原因。

编辑:这是文本框的一个已知问题,尚无解决方案。显然有解决方法。

于 2011-05-18T07:22:40.190 回答