文本框中的OnClick事件

I have a textbox in the webpage.

//.aspx

<td class="style2">Start of Date:<asp:TextBox ID="TextBox1" runat="server" 
            Height="22px" 
            ontextchanged="TextBox1_TextChanged" Width="157px"></asp:TextBox>
</td>

//aspx.cs

protected void cntCalendar_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = cntCalendar.TodaysDate.ToShortDateString();
}

Now I'm able to take the value in the textbox from calendar,but my problem is I'm not able to get the calendar to show onclick in the textbox and hide after date selected. Can anybody help me with this please.

Use the CalendarExtender class from the ASP.NET AJAX ToolKit.
Download and usage
You shouldn't do the post backs for the selecting date.

Sounds like you want to use something like the AJAX calendar extender. This control will negate the need of the asp:Calendar control.

See below for an example.

<asp:TextBox ID="txtStartDate" runat="server" CausesValidation="true" >
</asp:TextBox>
<ajax:CalendarExtender  ID="ce1" runat="server" Format="dd-MM-yyyy" TargetControlID="txtStartDate" PopupPosition="Right" >
</ajax:CalendarExtender>

The calendar will popup on click and when a date is selected, the textbox will be populated with the date selected in the format specified in the Format attribute

VMAtm is right on with the CalendarExtender.

However, if you have your own custom calendar you're using and you just need to manually pop that up via client onclick of the textbox, do this in Page_Load or PreRender:

TextBox1.Attributes["onclick"] = "showMyCalendar();";

or

TextBox1.Attributes[HtmlTextWriterAttribute.Onclick] = "showMyCalendar();";