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

Discussion in 'ASP .Net' started by champagne.supernova1974@googlemail.com, Nov 20, 2008.

  1. Guest

    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
    , Nov 20, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce W..1

    How to call Calendar DayRender event?

    Bruce W..1, Dec 9, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    8,742
    Bruce W..1
    Dec 9, 2003
  2. VB Programmer

    Calendar DayRender issue

    VB Programmer, Aug 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    437
    VB Programmer
    Aug 23, 2004
  3. VB Programmer

    How force DayRender event of Calendar to run?

    VB Programmer, Sep 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,130
    Scott Allen
    Sep 13, 2004
  4. =?Utf-8?B?UGV0ZXI=?=

    initializing a date in Calendar control with DayRender

    =?Utf-8?B?UGV0ZXI=?=, May 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    464
    Bruno Alexandre
    May 25, 2006
  5. RAB

    calendar dayrender event...

    RAB, Mar 4, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    668
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Mar 4, 2007
Loading...

Share This Page