Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have two textboxes in which I want to select dates from two calendar controls respectively. Now I have set the autopostback property of two textboxes to true. But it is not happening. Whenever I am selecting a date from the calendar, it is not reflecting in the textbox until a postback happens.

Below is my code:-
C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class _Default : System.Web.UI.Page 
{
    string stdt;
    string endt;
    string conn;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //txtfrmdt.Text = DateTime.Now.ToString();
        //txttodt.Text = DateTime.Now.ToString();
        if (!IsPostBack)
        {
            // string date2 = DateTime.Now.ToString();
            // string str = date2.Trim();
            //string date1 = str.Substring(0, 10);
            //string date1 = DateTime.Now.ToShortDateString();

            //DateTime dt = Convert.ToDateTime(date1);
            Calendar2.SelectedDate = DateTime.Now;
         //    Session["connstring"] = Request.QueryString["testupload"].ToString();
        }
            
            BindCalender();
           // bindgrid();

         //   DropDownList1.SelectedValue = Convert.ToString(Calendar1.SelectedDate);
         //   DropDownList1.SelectedItem.Text = Convert.ToString(Calendar1.SelectedDate);
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Calendar1.Visible = true;
      //  BindCalender();
    }
   
    protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
    {
        Calendar2.Visible = true;
    }
    public void BindCalender()
    {
        //txtfrmdt.Text = Calendar1.SelectedDate.ToString();
        //txttodt.Text = Calendar2.SelectedDate.ToString();
        stdt = Calendar1.SelectedDate.ToString();
        string s1 = stdt.Substring(0, 10);
        txtfrmdt.Text = s1.ToString();
        endt = Calendar2.SelectedDate.ToString();
        string s2 = endt.Substring(0, 10);
        txttodt.Text = s2.ToString();
        Calendar1.Visible = false;
        Calendar2.Visible = false;
      
        //Response.Redirect("Default2.aspx");
    }
   
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
       // DropDownList1.Text = Convert.ToString(Calendar1.SelectedDate);
     //   DropDownList1.SelectedItem.Text = Convert.ToString(Calendar1.SelectedDate);
        stdt = Calendar1.SelectedDate.ToString();
        string s1 = stdt.Substring(0, 10);
        txtfrmdt.Text = s1.ToString();
     
        

        //Calendar1 .SelectedDate 
    }
    protected void Calendar2_SelectionChanged(object sender, EventArgs e)
    {
        endt = Calendar2.SelectedDate.ToString();
        string s2 = endt.Substring(0, 10);
        txttodt.Text = s2.ToString();
    }
}


Please Help...
Posted
Updated 2-Jul-13 7:34am
v3
Comments
Sergey Alexandrovich Kryukov 1-Jul-13 9:13am    
What is "calender"?
—SA
rupai99 2-Jul-13 1:43am    
Mate,

It will be calendar...hope u know that...:)
Sergey Alexandrovich Kryukov 2-Jul-13 9:39am    
Oh yes, it sounds more familiar, thank you... :-)
Did you notice "Improve question" above?
—SA
rupai99 2-Jul-13 13:37pm    
Thanks mate.. ...I have changed accordingly :)

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900