开发者

Problem in using AutoPostback in asp.net c#

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜