drop down calendar disappear afer postback

J

Jeff

hi

asp.net 3.5

I'm trying to create a drop down calendar. It's based on this article I came
across on the Internet.
The problem is that when I click on the arrows to select previous or next
month, the calender disappear. So in my webpage where I use this control I
have to open the calendar again.. That doesn't look good. I think the
problem has something to do with postback and state. I'm not sure how to fix
this...

you got any suggestions?

Here is the markup:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CalendarControl.ascx.cs" Inherits="Controls_CalendarControl" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="..." onclick="OnClick()" /><br />
<div id="divCalendar" style="display:none; position:absolute;">
<asp:Calendar ID="Calendar1"
runat="server"
BackColor="gray"
OnSelectionChanged="Calendar1_SelectionChanged"
OnVisibleMonthChanged="Calendar1_MonthChanged" ></asp:Calendar>
</div>

<script type="text/javascript" >
function OnClick()
{
var cal = document.getElementById("divCalendar");
if (cal.style.display == "none")
{
cal.style.display = "";
}
else
{
cal.style.display = "none";
}
}
</script>
*****************************************************
Here is the code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Controls_CalendarControl : System.Web.UI.UserControl
{
DateTime _selecteddate;
public DateTime SelectedDate
{
get { return _selecteddate; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
_selecteddate = Calendar1.SelectedDate;
System.Web.UI.Control div = Page.FindControl("divCalendar");
if (typeof(HtmlGenericControl))
}
public DateTime Value()
{
if (TextBox1.Text.Length == 0)
return DateTime.MinValue;
else
return Convert.ToDateTime(TextBox1.Text);
}
protected override void Calendar1_MonthChanged(object sender,
MonthChangedEventArgs e)
{
// //this.Calendar1.
}
}
 
J

Jeff

solved, I implemented a runat="server" on the div. Removed the javascript.
And used c# code instead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top