Dynamically added usercontrol raised events

J

JC

I've tried and tried and this problem eludes me.
I have a form called "main" which has a div tag "DeptInfo" in which I
add my control "Information", here's the code.

---
Dim cont As New Control
cont = LoadControl("Information.ascx")
cont.ID = "Information"
DeptInfo.Controls.Add(cont)
---


At the top of main I added
---
Protected WithEvents Information As Information
---

In main I added
---
Private Sub Information_ProductSelectionChanged(ByVal sender As
Object, ByVal e As CommandEventArgs) Handles
Information.ProductSelectionChanged
'do my stuff here
End Sub
---

In the control information I have at the top
---
Public Event ProductSelectionChanged(ByVal sender As Object, ByVal e
As CommandEventArgs)
---

and raise the event on sel index changed for a ddl:
---
Dim evnt As New CommandEventArgs(DropDownList1.Items(DropDownList1.SelectedIndex).Text,
Nothing)
RaiseEvent ProductSelectionChanged(Me, evnt)
---

Here's the problem, this ALL works if the control as added at design
time by dragging the control onto the form. The event
"Information_ProductSelectionChanged" on form main fires.

How can I wire this up when adding the control dynamically?
How can I reference "main" from "information" and pass info without
having to generate an event?

Thanks for any help!!!
 
J

JC

For anyone having a similar problem here's what I did...

Dim WithEvents myUC1 As webusercontrol1

myUC1 = LoadControl("webusercontrol1.ascx")
myUC1 .ID = "myuc1id"
placeHolder1.Controls.Add(myUC1)

The diference is that I did not call the new() function and create
another control. Also I made public properties on the usercontrol to
pass info down to the usercontrol.

My thanks to Scott Mitchell from 4GuysFromRolla.com. It was very nice
of him to lend me a hand. If you're ever stuck look to their site!

Got to give credit where it is due.
Jeff
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top