Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My Ajax Calender Extender Not working, date not inserted in db.

Please help me

.aspx
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="plan_a_task_pop.aspx.cs" Inherits="plan_a_taskaspx" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="css/text.css" rel="stylesheet" type="text/css" />
    <link href="css/myclass.css" rel="stylesheet" type="text/css" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server" />
        <table width="100%" id="table1" runat="server">
        <tr>

XML
<td class="table_bold_text2" align="left">
                    Date of Execution:

                </td>
                <td>
                    <asp:TextBox ID="txt_date" runat="server" ReadOnly="true" CssClass="table_grey_border" Width="178" />
                    <ajaxToolkit:CalendarExtender Format="MM/dd/yyyy" ID="CalendarExtender2" runat="server" Enabled="True" TargetControlID="txt_date" CssClass="MyCalendar" />
                   
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Button ID="btn_submit" runat="server" Text="Submit" OnClick="btn_submit_OnClick" />
                </td>
            </tr>
        </table>
        <table id="table2" runat="server" visible="false">
            <tr>
                <td class="table_bold_text2">Dear user, your task has been submitted successfully.</td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>






.cs

protected void btn_submit_OnClick(object sender, EventArgs e)
{


string strqry = "";
string date = txt_date.Text;



strqry = "insert into tbl_order_task_details(order_id,buyer_name,date_of_execution,subject,detail_of_task, assigned_to,Category,SubCategory) values('" + Session["order_id"].ToString() + "','" + ViewState["customer_id"].ToString() + "','" + date.ToString() + "','" + tt_subject.Text.ToString().Replace("'", "''") + "','" + tt_details_of_the_task.Text.ToString().Replace("'", "''") + "', '" + ddl_user.SelectedValue.ToString() + "','" + ddl_category.SelectedItem.ToString() + "','" + ddl_subCategory.SelectedItem.ToString() + "')";

obj.openDatabase();
obj.executeMySqlqry(strqry);
obj.closeDatabase();
tt_details_of_the_task.Text = "";
tt_subject.Text = "";
ddl_subCategory.Items.Clear();
ddl_category.Items.Clear();
ddl_user.Items.Clear();

}
Posted
Updated 3-Jan-14 18:23pm
v5
Comments
Sergey Alexandrovich Kryukov 4-Jan-14 0:28am    
Excuse me, what is "calender"?
—SA

Remove ReadOnly="true" on the textbox...

Consider to set readonly attribute on textbox by client code....go through this link for more info

Read This
 
Share this answer
 
Comments
arvind bisht 4-Jan-14 9:13am    
thanks sir, I will try it on my next working day. thanku so much
I hope you are using a stored procedure to save the date to the database and also access the picked date in a textbox.
Here's a solution which i can think of

C#
sqlCmd.Parameters.Add("@date",SqlDbType.DateTime).Value=Convert.ToDateTime(txtDate.Text);
 
Share this answer
 
Comments
arvind bisht 4-Jan-14 0:24am    
No i am not using stored procedure, please see the above code
Try this

C#
DateTime.Parse(txt_date.Text).ToString("MM/dd/yyyy")


You can also use DateTime.TryParse...

C#
DateTime date=DateTime.Now;

DateTime.TryParse(txt_date.Text,out date);

date.ToString("MM/dd/yyyy");
 
Share this answer
 
v3
Comments
arvind bisht 4-Jan-14 4:34am    
this is not working
[no name] 4-Jan-14 7:53am    
are you getting a parse error? or the main problem is still not resolved...

What is the datatype of your date field in the database?
arvind bisht 4-Jan-14 8:41am    
Sir, my textbox "txt_date.Text" getting empty, Not pick any date from calender extender

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