how to display calendar only by code behind

Posted by Rimjhim4 under ASP.NET on 2/16/2012 | Points: 10 | Views : 11941 | Status : [Member] | Replies : 16
i m working in asp.net with c#,i have a textbox, my question is that when i click on the textbox, calendar will be diaplay.
how it is possible? pls tell me




Responses

Posted by: SureshMongam on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

The ASP.NET ajax calendar you refer to is an extender, so in theory you could add it to your textbox at runtime in the code-behind. See the example below:

<body>
<form id="form1" runat="server"><asp:scriptmanager runat="server"></asp:scriptmanager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:PlaceHolder ID="Place1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>

Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CalendarExtender myCalExt = new CalendarExtender();
myCalExt.TargetControlID = "TextBox1";
Place1.Controls.Add(myCalExt);
}
}
}

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
i want the solution of this problem in asp 2.0
i m using asp 2.0

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/16/2012 [Member] Silver | Points: 25

Up
0
Down
Hi ,
If you want to add a calendar to Form during runtime the following code can be used.
  protected void Page_Load(object sender, EventArgs e)

{
Calendar cal = new Calendar();
this.form1.Controls.Add(cal);

}


Thanks,
Sanjay

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
its not working..............

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/16/2012 [Member] Silver | Points: 25

Up
0
Down
Its working fine here?
Whats the error you get?
Let me know.

Thanks,
Sanjay

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/16/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
Attached is the working copy , what i wrote.
 Download source file

Thanks,
Sanjay

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
there is no error in the compile but its not show any calendar pls mind i m working in asp 2.0

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
there is no error in the compile but its not show any calendar pls mind i m working in asp 2.0

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
its working but how to select date??

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/17/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
Try this

 protected void Page_Load(object sender, EventArgs e)

{
Calendar cal = new Calendar();
//cal.ID = "calID";
cal.SelectionChanged+=new EventHandler(cal_SelectionChanged);
this.form1.Controls.Add(cal);

}
protected void cal_SelectionChanged(object sender, EventArgs e)
{
Calendar cal = sender as Calendar;
Response.Write(cal.SelectedDate);
}


Thanks,
Sanjay

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Try CalendarExtenderControl in Ajax Toolkit

gowthaman8870226416

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sekar.c on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try this code
<table>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="FromDate"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtfromDate" runat="server" AutoPostBack="True" ontextchanged="txtfrom_TextChanged" Width="150px">
</asp:TextBox>
<asp:CalendarExtender ID="txtfrom_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtfromDate">
</asp:CalendarExtender>
</td>
</tr>
</table>

Regard
Sekar.c


Regards
Sekar.c

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj_chennai on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
hi
use this in your design page after including ajax toolkit in your toolbox..
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server"
Enabled="True" TargetControlID="TextBox1">
</asp:CalendarExtender>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>

raj

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/22/2012 [Member] Starter | Points: 25

Up
0
Down
hi Sksamantaray...........
can u pls tell me why this code is not working at button_click



{

Calendar cal = new Calendar();

//cal.ID = "calID";

cal.SelectionChanged+=new EventHandler(cal_SelectionChanged);

this.form1.Controls.Add(cal);



}
u know its proper work at page_load..................
pls tell me............whats the mistake

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/22/2012 [Member] Silver | Points: 25

Up
0
Down


Did you add this in code behind as well?

protected void cal_SelectionChanged(object sender, EventArgs e)

{

Calendar cal = sender as Calendar;

Response.Write(cal.SelectedDate);

}

Thanks,
Sanjay

Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rimjhim4 on: 2/22/2012 [Member] Starter | Points: 25

Up
0
Down
yeah i already used all the things ..........
i told you this code is not working at button_click,but the same code is working in page load.........
i cant understand whats the problem .................
pls help me..................


Rimjhim4, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response