Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > AddHandler doesn't work in Page_PreRender()

Reply
Thread Tools

AddHandler doesn't work in Page_PreRender()

 
 
news.microsoft.com
Guest
Posts: n/a
 
      10-21-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AddHandler in C# doesn't work Bjorn Sagbakken ASP .Net 5 10-29-2007 02:49 PM
AddHandler doesn't seem to work. SimonM ASP .Net Web Controls 3 06-04-2005 07:35 AM
AddHandler to Dropdownlist in ItemDataBound Doesnt work !! =?Utf-8?B?Q2xvdWRz?= ASP .Net 3 08-30-2004 02:58 AM
Re: Help w/AddHandler (Not Firing Off) Natty Gur ASP .Net 1 08-11-2003 03:06 PM
Help w/AddHandler (Not Firing Off) Jeffrey A. Voigt ASP .Net 3 08-11-2003 04:53 AM



Advertisments