Custominzation Calendar control in ASP 2.0

A

Alexandr Zverev

Hello.



I would like to develop control which will contain Calendar with some
addition logic in each cell. I found the way to customize each sell using
Calendar1_DayRender method which alow to :



TableCell c = ((DayRenderEventArgs)e).Cell;
c.Controls.Add(new TextBox());

This code shows textbox in each cell of the Calendar.



I said "great" and created simple custom control and tryed to put it on each
sell, but... it didn't show.

here is the code



public partial class DayCtrl : System.Web.UI.UserControl

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void LinkButton1_Click(object sender, EventArgs e)

{

this.Label1.Text = "invoked!";

}

protected override void Render(HtmlTextWriter writer)

{

base.Render(writer);
writer.Write("Say hello to all!");

}
}



And I also added code to Calendar1_DayRender method:



DayCtrl dc = new DayCtrl();

c.Controls.Add(dc);



Nothing but "Say hello to all!" - without any Labels, Buttons, which were on
control as well. I noticed what during invocation of it's Render method -
all children controls of DayCtrl were null.



"Ok" - said me. And changed code in Calendar1_DayRender method:



System.Web.UI.Control dc = Page.LoadControl("/calendar/DayCtrl.ascx");

//DayCtrl dc = new DayCtrl();

c.Controls.Add(dc);



Great. Control was shown. But I found out what the event of the LinkButton1
in this control doesn't invoking.

What's wrong how could I add simple user control to the cell of the Calendar
and catch events for buttons?



Alex Zverev
 
S

Steven Cheng[MSFT]

Hi Alex,

Welcome to ASPNET newsgroup.
Regarding on the creating dynamic controls in ASP.NET's Calendar control
and the sub control's postback event not fire problem, it is caused by the
following reason:

All the ASP.NET Control's postback event processing dependend on two
things:

#There is a eventhandler registered for control's certain event
# The event handler being registered before the runtime processing the event

Generally, the ASP.NET web page will process the postback events after page
load .. before page's PreRender event. So We must register the event
handler no late than Page_load.
So for your scenario, you add the dynamic created Usercontrol in the
calendar's DayRender event(I admit that this is the only availble one we
can make use of for the current ASP.NET buildin Calendar) which is after
page processing the postback event, so the postback event of the sub
controls (we added dynamically in DayRender) won't be fired.

So currently for the ASP.NET buildin Calendar control, the dayRender event
is capable of helping adding some display only controls, for those ones
which also need post back event handling, I'm afraid, we may need to look
for some other Calendar controls or implemet a custom one.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| From: "Alexandr Zverev" <[email protected]>
| Subject: Custominzation Calendar control in ASP 2.0
| Date: Thu, 28 Jul 2005 21:35:16 +0400
| Lines: 93
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
| NNTP-Posting-Host: 78.130.leased.lanck.net 62.152.78.130
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingcontrols:3944
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
|
| Hello.
|
|
|
| I would like to develop control which will contain Calendar with some
| addition logic in each cell. I found the way to customize each sell using
| Calendar1_DayRender method which alow to :
|
|
|
| TableCell c = ((DayRenderEventArgs)e).Cell;
| c.Controls.Add(new TextBox());
|
| This code shows textbox in each cell of the Calendar.
|
|
|
| I said "great" and created simple custom control and tryed to put it on
each
| sell, but... it didn't show.
|
| here is the code
|
|
|
| public partial class DayCtrl : System.Web.UI.UserControl
|
| {
|
| protected void Page_Load(object sender, EventArgs e)
|
| {
|
| }
|
| protected void LinkButton1_Click(object sender, EventArgs e)
|
| {
|
| this.Label1.Text = "invoked!";
|
| }
|
| protected override void Render(HtmlTextWriter writer)
|
| {
|
| base.Render(writer);
| writer.Write("Say hello to all!");
|
| }
| }
|
|
|
| And I also added code to Calendar1_DayRender method:
|
|
|
| DayCtrl dc = new DayCtrl();
|
| c.Controls.Add(dc);
|
|
|
| Nothing but "Say hello to all!" - without any Labels, Buttons, which were
on
| control as well. I noticed what during invocation of it's Render method -
| all children controls of DayCtrl were null.
|
|
|
| "Ok" - said me. And changed code in Calendar1_DayRender method:
|
|
|
| System.Web.UI.Control dc = Page.LoadControl("/calendar/DayCtrl.ascx");
|
| //DayCtrl dc = new DayCtrl();
|
| c.Controls.Add(dc);
|
|
|
| Great. Control was shown. But I found out what the event of the
LinkButton1
| in this control doesn't invoking.
|
| What's wrong how could I add simple user control to the cell of the
Calendar
| and catch events for buttons?
|
|
|
| Alex Zverev
|
|
|
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top