Putting a hyperlink in a Calendar Control

T

Tina

This does not work...
Private Sub calWO_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles calWO.DayRender
If e.Day.Date.Day = 18 Then
Dim myControl As New LiteralControl("<a
href='http://www.google.com'></a>")
e.Cell.Controls.Add(myControl)
End If
End Sub

Anyone know why not?
Thanks,
T
 
G

Guest

Hello Tina.

I'd suggest using a HTMLGenericControl rather than a literal.

This is a c# version i use, it may help:

//the function to render the days of the calendar as specified by us
private void Calendar1_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
//clear the controls that are rendered automatically
//by the calendar control

e.Cell.Controls.Clear();

//Create a new link control
System.Web.UI.HtmlControls.HtmlGenericControl Link = new
System.Web.UI.HtmlControls.HtmlGenericControl();

Link.TagName = "a";
Link.InnerText = e.Day.DayNumberText;

//set the href value to the javascript function to select the date
Link.Attributes.Add("href", "Javascript:SelectDate('" +
e.Day.Date.ToString("d") + "');");

//set the color of the link
Link.Attributes.Add("style", "color:#000000;");

//add our link control to the day
e.Cell.Controls.Add(Link);
}
 
T

Tina

odd but I found that very same code snippet at dotpitchstudios.com.

I can't seem to convert....

Link.Attributes.Add("href", "Javascript:SelectDate('" +
e.Day.Date.ToString("d") + "');");

to VB that will not get an error.
T
 

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,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top