Groups | Blog | Home
all groups > asp.net > january 2004 >

asp.net : Handlers and dynamic buttons


noone
1/26/2004 11:18:24 PM
Below are the guts to a function that returns a textbox and button. A
handler is added to the button. All this is done in a class separate from
the code behind including the Handler.

So here is the problem, unless I regenerate the buttons, when I post back
the handler for the button pressed does not fire. What do I need to do to
make this handler work?





Dim p As New PlaceHolder
Dim btn As New ImageButton
Dim txt As New TextBox
txt.Text = "1"
txt.ID = "txt" & Detail.Asin

txt.Width = Unit.Pixel(20) '
txt.EnableViewState = True

btn.CommandArgument = Detail.Asin

btn.ImageUrl = "amzImages/add-to-cart-02.gif"

btn.ID = "btn" & Detail.Asin

btn.EnableViewState = True

AddHandler btn.Click, AddressOf Purchase_AddToCart

p.Controls.Add(btn)

p.Controls.Add(New Web.UI.LiteralControl("<br>Qty: "))

p.Controls.Add(txt)

p.Controls.Add(New Web.UI.LiteralControl("&nbsp"))

Return p



x-- 100 Proof News - http://www.100ProofNews.com
x-- 3,500+ Binary NewsGroups, and over 90,000 other groups
x-- Access to over 800 Gigs/Day - $8.95/Month
x-- UNLIMITED DOWNLOAD
Natty Gur
1/27/2004 3:30:01 AM
Hi,

If I get you right, you must recreate and attach events to dynamically
added controls every time page is loaded including post backs.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377


*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button