dynamicly add link button to calendar cel

G

Guest

I am trying to add a link button to a calendar.
this is a simple example:
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
If e.Day.Date = Now.Date Then
Dim lbtntemp As New LinkButton
lbtntemp.Text = "go here"
lbtntemp.ID = "thsLnk"
e.Cell.Controls.Add((lbtntemp))
End If
End Sub
3. issues
1. i do not have a link, only text
2. i want to pass parameter(s) withthe link
3. how can i add a <br> to the cell if i want to add multile items?

Thanks!!!
kes
 
K

Karl Seguin

You should read the DayRender documentation:

Note Since the DayRender event is raised while the Calendar control is
being rendered, you cannot add a control that can also raise an event, such
as LinkButton. You can only add static controls, such as
System.Web.UI.LiteralControl, Label, Image, and HyperLink.

I guess you're stuck with using a <a href=....> and pass something in the
querystring..


AS for your <br> question, try:

e.Cell.Controls.Add(New LiteralControl("<br>"))

Karl
 
G

Guest

What works for me is to set the SelectionMode Property to "Day." At this
point .Net automatically converts the day number as a linkbutton, which you
can use to capture which day the user selects!

To do that you use the calendar's SelectionChanged event to capture the
SelectedDate property:
(This is from MSDN under the SelectedDate property topic)
Label1.Text = "The selected date is " &
Calendar1.SelectedDate.ToShortDateString()

Since you now have the date the user selected, you can do such things as
populate a datagrid with the different items that are on that day from a
database.

Hope this helps.
Richard
 
G

Guest

here is an odd one. I was able to add alink button and it can post back here
is how:
If e.Day.Date = Now.Date Then

Dim lbtntemp As New LinkButton
lbtntemp.Text = "go here"
lbtntemp.ID = "thsLnk"
lbtntemp.CommandName = "ths One"
lbtntemp.CommandArgument = "1"
lbtntemp.Attributes("onClick") =
"javascript:__doPostBack('LinkButton1','2day')"

e.Cell.Controls.Add(lbtntemp)
Dim btnbx1 As New Button
btnbx1.ID = "mytxt"
btnbx1.Text = "go"
btnbx1.CommandArgument = "ths" & Now.Date
btnbx1.CommandName = "ok_GO"

e.Cell.Controls.Add(btnbx1)
' DataBind()

End If
the link did work. The button did also, but not the way i wanted. I'm still
working onthis do you want me, but made some progress.
do you want me to keep you posted?
thanks
kes
 
K

Karl Seguin

Kurt:
Posting updates is always helpful to others who run into the same problems
you do. It's a shame you need to go through that extra effort, but does
seem like the only way to get things going. You might benefit from using a
3rd party control other than the built-in calendar.

I've always liked the free EwolrdUI one:
http://www.eworldui.net/CustomControls/CalendarPopupDemo.aspx

though I don't know if it'll solve your problem any better...

Karl
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top