Commmon handling of Calendar controls

G

Guest

I have around 20 calendar controls on my screen besides 20 textboxes.
The functionality of each control is the same, they take in a parameter for
the textbox name and open a calendar in a popup. And on selection the
textbox -identified by the name passed in the querystring , is populated.

Now, the 20 controls will have 20 event handlers. Is there a way I can have
one function (or event handler ) which would handle all the 20 calls.
What I mean is that instead of having different event handlers for each
calendar control, can I have just one for each of them ? And based on the
parameter passed I would identify the textbox?
 
G

Guest

Use any of the following options:
1- Declaratively:
<asp:Calendar ID="calender1" Runat="server"
OnSelectionChanged="Calenders_SelectionChanged"></asp:Calendar>
<asp:Calendar ID="calender2" Runat="server"
OnSelectionChanged="Calenders_SelectionChanged"></asp:Calendar>

and so on..

2- in the code behind, add statements in the Page.Init eventhandler:

a. For C#,
this.calender1.SelectionChanged += new
System.EventHandler(this.Calenders_SelectionChanged);
this.calender2.SelectionChanged += new
System.EventHandler(this.Calenders_SelectionChanged);

b. For VB:
AddEventHandler calender1.SelectionChanged , AddressOf
Calenders_SelectionChanged

or
Private sub Calenders_SelectionChanged(sender as object, e as EventArgs )
handles calender1.SelectionChanged , calender2.SelectionChanged

In the method that handles the event:
private void Calenders_SelectionChanged(object sender, System.EventArgs e)
{
switch (((Calendar)sender).ID)
{
case "calender1": //process calender1
break;
case "calender2": //process calender2
break;
}
}
 

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,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top