Can't access control created in Calendar 'DayRender' event

  • Thread starter champagne.supernova1974
  • Start date
C

champagne.supernova1974

Hi

Can anyone help with a quick question?

I am adding a textbox into each "day" cell of a calendar control, by
using the following code in the DayRender event:


Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DayRenderEventArgs) Handles
Calendar1.DayRender
If Not e.Day.IsOtherMonth Then
Dim txtDayCell As New TextBox
txtDayCell.ID = "txtMonth" & e.Day.DayNumberText
e.Cell.Controls.Add(txtDayCell)
End If
End Sub


My problem is that when I then try to access the textbox value in
PageLoad, I get an 'Object reference not set to an instance of an
object' error at the line I've highlighted in my 'test' code below


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim txtMonth1 As New TextBox
txtMonth1 = Page.FindControl("txtMonth1")

Dim Button1 As New Button
Button1 = Page.FindControl("Button1")

If Me.IsPostBack Then
Button1.Text = txtMonth1.Text **** Error is thrown here
*****
End If

End Sub


I suspect I've not quite got my timing right with the page lifecycle
side of this - could anyone suggest how I can access the textboxes in
the calendar cells. from a postback?

Many thanks for your help guys.

Mark
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top