By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

dynamicly add link button to calendar cel

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
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
"Kurt Schroeder" wrote:
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

Nov 19 '05 #3

P: n/a
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
"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
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


Nov 19 '05 #4

P: n/a
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/CustomContro...PopupDemo.aspx

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

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
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
"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in
message
news:0E**********************************@microsof t.com...
>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


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.