Link to home
Start Free TrialLog in
Avatar of KMusatoff
KMusatoff

asked on

ASP.NET Dynamic User Control Fire Parent Event in VB

I have a parent page with a simple code to load user controls. The question that I have is how can I fire MenuLinkButton_Click() on parent from loaded user control (any loaded user control) without explicitly declaring that user control on parent page?


Code provided...

Thank You

Kevin

 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    LoadUserControl()
End Sub
Protected Sub MenuLinkButton_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
    If Not String.IsNullOrEmpty(e.CommandName) Then LastLoadedControl = BASE_PATH & e.CommandName & ".ascx"
    LoadUserControl()
End Sub
Private Sub LoadUserControl()
    Dim controlPath As String = LastLoadedControl
    Dim bodyPlaceHolder As ContentPlaceHolder = Master.FindControl("body")

    If Not String.IsNullOrEmpty(controlPath) Then
         bodyPlaceHolder.Controls.Clear()
         Dim uc As Control = Page.LoadControl(controlPath)
         uc.ID = "loadedControl"
         bodyPlaceHolder.Controls.Add(uc)
    End If
End Sub

Open in new window

Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

Hi, try this code


MainForm.Controls(Parent).YourControlName
Avatar of KMusatoff
KMusatoff

ASKER

The idea is to run Sub MenuLinkButton_Click() on parent
from your page
try to find the control in your parent
then yourControl.Click(sender,e)
convert to the template .
ASKER CERTIFIED SOLUTION
Avatar of KMusatoff
KMusatoff

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Self founded solution