0

I am trying to disable the page refresh every time when I click a date in the calendar. The Calendar is created from the code behind since I am using AjaxToolkit Accordion for my project.

Here is my code, it is working, but it will refresh the page every time when I click a date and I want to prevent that.

TextBox txtDate = new TextBox();
txtDate.ID = "dateTxt" + taskID;

Calendar dateddl = new Calendar();
dateddl.ClientIDMode = ClientIDMode.Inherit;
dateddl.ID = "dateddl" + taskID;
dateddl.SelectionChanged += new EventHandler(Dateddl_SelectionChanged);

and the code for Dateddl_SelectionChanged

protected void Dateddl_SelectionChanged(object sender, EventArgs e)
    {
        Calendar dateddl = (Calendar)sender;
        string dateddlID = dateddl.ID;
        string index = dateddlID.Substring(dateddlID.IndexOf('l') + 1);
        TextBox textBox = (TextBox)FindControlRecursive(Page, $"dateTxt{index}");
        dateddl.Style.Add("display", "none");
        textBox.Text = dateddl.SelectedDate.ToShortDateString();//.ToString("MM/dd/yyyy");
    }

These are the code I have in the code behind. Textbox and Calendar are in a function that will be called in both IsPostBack and !IsPostBack.

Is it possible to prevent postback in EventHandler or some where in the code behind? Or maybe instead of using EventHandler I can handle asp.net calendar from jquery?

Client code:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder2" >
<div style="height: 867px; width:1100px; margin-top:10%;" >

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <br />
    <asp:Panel ID="MyContent" runat="server">  
        <ajaxToolkit:Accordion  ID="MasterAccordion" runat="server"> </ajaxToolkit:Accordion>
    </asp:Panel>  

</div>

</asp:Content>

Lucia
  • 47
  • 6

0 Answers0