I have the following ImageButton, which toggles the visibility property of a calendar control.

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/calendar.png" OnClick="Display_Calendar1"/>

Problem is, when I click on it, it sends a postback command which conflicts with some of my other code. I've seen there are multiple threads about this where the most common solution is to call "return false;" on the OnClick event. However, I still need to run the calendar toggle method:

//cStart_Date is the calendar control and tbStart_Date is a textbox where I write down the chosen date.
protected void Display_Calendar1(object sender, ImageClickEventArgs e)  
{
    if (IsValidDate(tbStart_Date.Text))
    {
        cStart_Date.SelectedDate = Convert2Date(tbStart_Date.Text);
        cStart_Date.VisibleDate = cStart_Date.SelectedDate;
    }
    cStart_Date.Visible = !cStart_Date.Visible;
}

In all the examples I've seen, the function ran before the "return false;" is a JavaScript function, but I want it to run my C# method. This results in a Server error when I launch it on the browser, displaying Compiler Error Message: CS1026:) expected

I've also tried the method without arguments protected void Display_Calendar1() but the result is the same...

Related posts

Recent Viewed