AddHandler doesn't work in Page_PreRender()

Discussion in 'ASP .Net Web Controls' started by news.microsoft.com, Oct 21, 2004.

  1. I need to move the FOR in the following code, which dynamically creates an
    array of textbox, dropdown, button object, and handlers, from the
    Page_Load() event to the Page_PreRender() event.

    Control events change my rendering, so the Page_Load() is too soon, but I
    can't get the dynamically handers created with the AddHandler method to fire
    when they are created in the Page_PreRender() event.

    Is there another method for creating the handler or another event before
    Page_PreRender()?

    Any suggestions would be appreciated?

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    Dim i As Integer

    If Not IsPostBack Then viewstate(m_sObjectID & "_Count") = 1

    plhContent.Controls.Add(New LiteralControl("<TABLE border=1>"))

    Dim btnButton As Button = New Button

    plhContent.Controls.Add(New LiteralControl("<TR><TD>"))

    btnButton.Text = "Add Additional Text"

    btnButton.ID = m_sObjectID & "_I_0"

    AddHandler btnButton.Click, AddressOf Insert_Click

    plhContent.Controls.Add(btnButton)

    plhContent.Controls.Add(New LiteralControl("</TD></TR>"))

    End Sub

    Sub Insert_Click(ByVal sender As Object, ByVal e As EventArgs)

    viewstate(m_sObjectID & "_Count") += 1

    AddSegment(viewstate(m_sObjectID & "_Count"))

    End Sub

    Sub AddSegment(ByVal index As Integer)

    Dim litLabel As LiteralControl

    Dim txtTextBox As TextBox, ddlDropDownList As DropDownList, btnButton As
    Button

    plhContent.Controls.Add(New LiteralControl("<TR><TD>"))

    txtTextBox = New TextBox

    txtTextBox.ID = m_sObjectID & "_1_" & index

    plhContent.Controls.Add(txtTextBox)

    plhContent.Controls.Add(New LiteralControl("</TD><TD>"))

    ddlDropDownList = New DropDownList

    ddlDropDownList.ID = m_sObjectID & "_2_" & index

    plhContent.Controls.Add(ddlDropDownList)

    plhContent.Controls.Add(New LiteralControl("</TD><TD>"))

    btnButton = New Button

    btnButton.Text = "Insert Line #" & index

    btnButton.ID = m_sObjectID & "_I_" & index

    AddHandler btnButton.Click, AddressOf Insert_Click

    plhContent.Controls.Add(btnButton)

    plhContent.Controls.Add(New LiteralControl("</TD></TR>"))

    End Sub

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles MyBase.PreRender

    Dim i As Integer

    For i = 1 To viewstate(m_sObjectID & "_Count") : AddSegment(i) : Next

    plhContent.Controls.Add(New LiteralControl("</TABLE>"))

    End Sub
     
    news.microsoft.com, Oct 21, 2004
    #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. Ashish

    Page_Prerender

    Ashish, Sep 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    499
    Ashish
    Sep 24, 2004
  2. Ashish

    page_prerender

    Ashish, Sep 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,872
    Jonathan Allen
    Sep 25, 2004
  3. =?Utf-8?B?Q2xvdWRz?=
    Replies:
    3
    Views:
    8,429
    Scott Allen
    Aug 30, 2004
  4. Bjorn Sagbakken

    AddHandler in C# doesn't work

    Bjorn Sagbakken, Oct 28, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    5,946
    Cowboy \(Gregory A. Beamer\)
    Oct 29, 2007
  5. SimonM

    AddHandler doesn't seem to work.

    SimonM, Jun 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    227
    Teemu Keiski
    Jun 4, 2005
Loading...

Share This Page