Click here to Skip to main content
15,877,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am displaying a calender inside a panel.

And I want to show the calender only when the button is clicked.

I have tried but it's not coming.

Please help.

C#
static int flag = 0;
protected void Page_Load(object sender, EventArgs e)
{
    if (flag == 1)
    {
        pnlCal1.Visible = true;
    }
    if (flag == 0)
    {
        pnlCal1.Visible = false;
    }
    if (!IsPostBack)
    {
        flag = 1;
        pnlCal1.Visible = false;
    }
}
protected void imgDate1_Click(object sender, ImageClickEventArgs e)
{
    pnlCal1.Visible = true;
}

protected void calDate1_SelectionChanged(object sender, EventArgs e)
{
    txtDate1.Text = calDate1.SelectedDate.ToShortDateString();
    //pnlCal1.Visible = false;
    flag = 0;
}


Please help
Posted

Hi,
       Here you have not specified which calender you are using(either inbuilt calender control or third party tool). But according to your situation i think you are using inbuilt calender control.
Then you can do it like this.
XML
//design side
//make by default visible false
<asp:Panel ID="pnlCal1" runat="server" Visible="false">
      <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</asp:Panel>
<asp:ImageButton ID="imgDate1" runat="server" OnClick="imgDate1_Click" />

C#
protected void Page_Load(object sender, EventArgs e)
{
    // you don't need to do complex logic here!!!!!
}

protected void imgDate1_Click(object sender, ImageClickEventArgs e)
{
    pnlCal1.Visible = true;  // just make visible here
}

Hope it helps you.
Thanks.
 
Share this answer
 
v3
Markup:

XML
<asp:Button ID="Button1" runat="server" Text="show panel"
       OnClick="Button1_Click" />
   <asp:Label ID="Label1" runat="server"></asp:Label>
   <asp:Panel ID="Panel1" runat="server" Visible="false">
       <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
       </asp:Calendar>
   </asp:Panel>

HTML



Code behind:

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = true;
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        Label1.Text = Calendar1.SelectedDate.ToLongDateString();
    }

C#

 
Share this answer
 

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