<asp:Calendar> question

J

js

Any way to modify an <asp:Calendar> tag with parameters on the fly? Seems
I'm not allowed to use the <% =xxx %> substitution for parameters to the
<asp:Calendar> tag.

Do I have to do code behind procedures to intercept the creation of the
Calendar to modify the parameters using DOM?

Looking to generate multiple calendars, for different months, using a C#
programming loop rather than in-line code in the .aspx file.
 
K

Ken Cox [Microsoft MVP]

Maybe this isn't what you're after, but it sounds like you might be able to
put a placeholder control on the form and then add your calendars
programmatically in the code behind. The following is C#, converted from VB
by Lutz Roeder's .NET Reflector (http://www.aisto.com/roeder/dotnet/)

private void Page_Load(object sender, EventArgs e)
{ Calendar calendar1;
DateTime time1;
int num1;
DateTime time2;
num1 = 1;

L_0003:
calendar1 = new Calendar();
time2 = DateTime.Now;
calendar1.TodaysDate = time2.AddMonths(num1);
time2 = DateTime.Now;
calendar1.SelectedDate = time2.AddMonths(num1);
this.PlaceHolder1.Controls.Add(calendar1);
num1 = (num1 + 1);
if (num1 <= 12)
{
goto L_0003;

}

}


<form id="Form1" method="post" runat="server">
<asp:placeHolder id="PlaceHolder1" runat="server"></asp:placeHolder>
</form>


VB Code is here:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim calGen As Calendar
Dim intMonths As Integer
Dim dt As DateTime
For intMonths = 1 To 12
calGen = New Calendar
calGen.TodaysDate = Date.Now.AddMonths(intMonths)
calGen.SelectedDate = Date.Now.AddMonths(intMonths)
PlaceHolder1.Controls.Add(calGen)
Next
End Sub
 
J

js

thanks, I'll try it.


Ken Cox said:
Maybe this isn't what you're after, but it sounds like you might be able to
put a placeholder control on the form and then add your calendars
programmatically in the code behind. The following is C#, converted from VB
by Lutz Roeder's .NET Reflector (http://www.aisto.com/roeder/dotnet/)

private void Page_Load(object sender, EventArgs e)
{ Calendar calendar1;
DateTime time1;
int num1;
DateTime time2;
num1 = 1;

L_0003:
calendar1 = new Calendar();
time2 = DateTime.Now;
calendar1.TodaysDate = time2.AddMonths(num1);
time2 = DateTime.Now;
calendar1.SelectedDate = time2.AddMonths(num1);
this.PlaceHolder1.Controls.Add(calendar1);
num1 = (num1 + 1);
if (num1 <= 12)
{
goto L_0003;

}

}


<form id="Form1" method="post" runat="server">
<asp:placeHolder id="PlaceHolder1" runat="server"></asp:placeHolder>
</form>


VB Code is here:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim calGen As Calendar
Dim intMonths As Integer
Dim dt As DateTime
For intMonths = 1 To 12
calGen = New Calendar
calGen.TodaysDate = Date.Now.AddMonths(intMonths)
calGen.SelectedDate = Date.Now.AddMonths(intMonths)
PlaceHolder1.Controls.Add(calGen)
Next
End Sub
 

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,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top