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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • champagne.supernova1974@googlemail.com

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

    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_DayRe nder(ByVal sender As Object, ByVal e
    As System.Web.UI.W ebControls.DayR enderEventArgs) Handles
    Calendar1.DayRe nder
    If Not e.Day.IsOtherMo nth Then
    Dim txtDayCell As New TextBox
    txtDayCell.ID = "txtMonth" & e.Day.DayNumber Text
    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.EventArg s) Handles Me.Load

    Dim txtMonth1 As New TextBox
    txtMonth1 = Page.FindContro l("txtMonth1" )

    Dim Button1 As New Button
    Button1 = Page.FindContro l("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
Working...