Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2005, 11:24 PM
Authorized User
 
Join Date: Jun 2004
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default Calendar control postback problem

I have one calendar control where the textbox will be filled with date after I click on any day from the calendar control. The problem is that I can't update my data to database. But, the data can be updated into database only 'if' I type in date manually into the textbox. Is it a postback problem? How can I solve this problem?

 
Old February 12th, 2005, 01:35 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Please post your code, I am not sure what you are trying to do. Are you using the VS calendar control, or a third party control? Are you populating the textbox with the date when the user clicks the calendar control?
 
Old February 12th, 2005, 10:12 AM
Authorized User
 
Join Date: Jun 2004
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default

Here is my coding:

 
Quote:
quote:// Web control declaration
Quote:
protected System.Web.UI.WebControls.TextBox txtDate1;
protected System.Web.UI.WebControls.TextBox txtDate3;
protected System.Web.UI.WebControls.TextBox txtDate2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox txtRefNum;
protected System.Web.UI.WebControls.Calendar Calendar1;

// Nothing in my Page Load function
private void Page_Load(object sender, System.EventArgs e)
{
    // Put user code to initialize the page here
}

// Date string is inserted into textbox after date selection from calendar control
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
    bool DateIsInserted = false;

    if(txtDate1.Text == "" && DateIsInserted == false)
    {
    txtDate1.Text = Calendar1.SelectedDate.ToString("d/M/yyyy");
    DateIsInserted = true;
    }
    if(txtDate2.Text == "" && DateIsInserted == false)
    {
    txtDate2.Text = Calendar1.SelectedDate.ToString("d/M/yyyy");
    DateIsInserted = true;
    }
    if(txtDate3.Text == "" && DateIsInserted == false)
    {
    txtDate3.Text = Calendar1.SelectedDate.ToString("d/M/yyyy");
    DateIsInserted = true;
    }
}

// Update to database with button click
private void UpdateDataToDB()
{
    string connectionString="server=(local);database=myDB;" +
        "integrated security=true;Trusted_Connection=Yes;";

    SqlConnection DbConnection = new SqlConnection(connectionString);

    SqlTransaction Tran;

    DbConnection.Open();
    Tran = DbConnection.BeginTransaction();

    try
    {
        string queryString = "INSERT INTO Payment(RefNum, Date1, " +
            "Date2, Date3)" +
            "Values(@ReservationRefNum, @Date1, @Date2, @Date3)";

        SqlCommand CommandString = new SqlCommand(queryString, DbConnection);
        CommandString.Transaction = Tran;

        SqlParameter RefNumParam = new SqlParameter("@RefNum", SqlDbType.VarChar, 50);
        RefNumParam.Value = txtRefNum.Text;
        CommandString.Parameters.Add(RefNumParam);

        SqlParameter Date1Param = new SqlParameter("@Date1", SqlDbType.DateTime);
        Date1Param.Value = txtDate1.Text;
        CommandString.Parameters.Add(Date1Param);

        SqlParameter Date2Param = new SqlParameter("@Date2", SqlDbType.DateTime);
        Date2Param.Value = txtDate2.Text;
        CommandString.Parameters.Add(Date2Param);

        SqlParameter Date3Param = new SqlParameter("@Date3", SqlDbType.DateTime);
        Date3Param.Value = txtDate3.Text;
        CommandString.Parameters.Add(Date3Param);

        CommandString.ExecuteNonQuery();

        Tran.Commit();
        Response.Write("Success!");
    }
    catch
    {
        Tran.Rollback();
    }

    finally
    {
        DbConnection.Close();
    }
}
If you select the date using from the calendar control, you may find that you can't update to database. However, it is not the case if we key in text using keyboard.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar Control Postback x_ray ASP.NET 2.0 Basics 1 May 27th, 2007 03:56 AM
Problem with Microsoft Calendar Control in VB vgaya Pro VB 6 0 April 3rd, 2007 03:20 AM
catching the control that causes postback ACE2084 ASP.NET 1.0 and 1.1 Basics 1 February 22nd, 2005 04:00 PM
Problem with Calendar Control in VBA narendrapawar VB How-To 0 December 16th, 2004 09:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.