Solved

ASP.NET Dynamic User Control Fire Parent Event in VB

Posted on 2011-03-06
6
696 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:KMusatoff
6 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
Comment Utility
Hi, try this code


MainForm.Controls(Parent).YourControlName
0
 
LVL 3

Author Comment

by:KMusatoff
Comment Utility
The idea is to run Sub MenuLinkButton_Click() on parent
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
Comment Utility
from your page
try to find the control in your parent
then yourControl.Click(sender,e)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:lalitgada
Comment Utility
convert to the template .
0
 
LVL 3

Accepted Solution

by:
KMusatoff earned 0 total points
Comment Utility
I do not have a control on parent I can trigger. The loaded control will have many linkButtons to trigger controls.

But, never the less, I have found the way...

 
Protected Sub ControlLinkButton_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
    Dim p As Users_Default = CType(Context.Handler, Parent_Default) 'Parent_Default As Parent Page
    p.LastLoadedControl = e.CommandName
    p.LoadUserControl()
End Sub

Open in new window

0
 
LVL 3

Author Closing Comment

by:KMusatoff
Comment Utility
Self founded solution
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now