1

i have two text box controls with calender extender and a dropdownlist as follows.

<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>

What i want to do is when user selects a date in txtEndDate i want to call a function to load data in DropDownList1, i.e DataBind DropDownList1.

When i Set AutoPostBack property of txtEndDate to True and call a method on txtEndDate_TextChanged the event does not get fired.

Where am i going wrong can anyone help. I just want to load DropDownList1 when user selects a date in txtEndDate. What do i have to do.

here is what i had done in my 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");  
    }
}

I put the same event on ButtonClick event and everything worked fine.

6
  • are these codes wrapped in UpdatePanel ? Commented May 18, 2011 at 6:59
  • @Piyush , Very sorry, i dint get what you mean to say. Commented May 18, 2011 at 7:01
  • are all the controls (TextBox and DropDownList) inside of <asp:UpdatePanel></asp:UpdatePanel> Commented May 18, 2011 at 7:06
  • No. its inside <head><body><div><table><tr><td>...ASP CONTROLS..</> Commented May 18, 2011 at 7:09
  • just try and remove the ReadOnly="true" from txtEndDate control and see the results. Commented May 18, 2011 at 7:12

1 Answer 1

1

Try and remove the ReadOnly="true" from the TextBox control. This might solve your problem.

There is a problem with the TextBox controls having ReadOnly="true" that the value of the textbox is lost whenever PostBack happens and that is the reason why the event isn't firing.

Edit: It is a known issue with the textboxes which has no solution to it yet. there obviously are workarounds to it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.