Currently I am working on a Asp.Net app. It has a Asp.Net Calendar control and OnDayRender() method I am dynamically adding Checkbox control inside it. I am attaching CheckedChanged event handler too. But whenever I am clicking on checkbox it is not invoking the server side CheckedChanged() method. Any help would really be appreciated. Thanks.
Asp.Net code:
<div>
<asp:Calendar
ID="Calendar1"
runat="server"
NextPrevFormat="FullMonth"
ForeColor="WhiteSmoke"
SelectionMode="Day"
DayNameFormat="Full"
Font-Names="Book Antiqua"
Font-Size="Medium"
OnDayRender="Calendar1_DayRender">
</asp:Calendar>
</div>
Server side:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CheckBox checkBox1 = new CheckBox();
checkBox1.AutoPostBack = true;
checkBox1.Width = 25;
checkBox1.Enabled = false;
checkBox1.CheckedChanged = checkBox1_CheckedChanged;
e.Cell.Controls.AddAt(1, checkBox1);
e.Cell.Font.Size = FontUnit.XLarge;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
// Do some operation...
}
The Calendar's DayRender
event is exactly what is says it is - it's an event fired during the render process, just before the cell for the given day is rendered. Because this event is fired so late in the page life cycle , you cannot add controls that fire events.
From the Calendar documentation :
"Because the DayRender event is raised while the Calendar control is being rendered, you cannot add a control that can also raise an event, such as CheckBox. You can only add static controls, such as LiteralControl, Label, Image, and HyperLink."
Workaround here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.