<asp:Calendar> question

  • Thread starter Thread starter js
  • Start date Start date
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.
 
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
 
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
 
Back
Top