Groups | Blog | Home
all groups > asp.net building controls > november 2006 >

asp.net building controls : Dynamic controls button event in vb.net 2005


sushil prasad
11/15/2006 5:46:34 PM
I have created a control with some label, textbox and Button. On the click
of the button the entries in textbox on the control is validated and a
database table is updated. The button click event works when the
control is placed directly on the panel from design window but not when i
use
programming to load the control.
I need to be able to load the control dynamically into panel as this depends
on some selection user does in main window.

Here's how i load the control into panel:

panel1.controls.add(page.loadcontrol("MyControl.ascx"))

Thanks for help

Sushil



Gaurav Vaish (www.EdujiniOnline.com)
11/19/2006 12:00:00 AM
That's depends on where you are adding the control.

If you're adding it in CreateChildControls, it would work!


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://eduzine.edujinionline.com
-----------------------------------------


[quoted text, click to view]

Riki
11/20/2006 3:57:32 PM
Postback on dynamically created controls only works on two conditions:
1) the control needs to be dynamically added again AFTER the postback as
well (this is obvious, but may be forgotten!)
2) the control should have exactly the same ID as before the postback. If
the number of controls after the postback has changed, and the ID's are
assigned by the ASP.NET server automatically, this may cause an ID mismatch
and therefore postback failure. Either make sure that the number of controls
is the same, or that you force the same ID on the control as before the
postback.

I hope this helps...

--

Riki

[quoted text, click to view]

AddThis Social Bookmark Button