?
Solved

ASP.NET Dynamic User Control Fire Parent Event in VB

Posted on 2011-03-06
6
Medium Priority
?
704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35049953
Hi, try this code


MainForm.Controls(Parent).YourControlName
0
 
LVL 3

Author Comment

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

Expert Comment

by:Kamal Khaleefa
ID: 35053514
from your page
try to find the control in your parent
then yourControl.Click(sender,e)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:lalitgada
ID: 35053656
convert to the template .
0
 
LVL 3

Accepted Solution

by:
KMusatoff earned 0 total points
ID: 35064080
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
ID: 35115463
Self founded solution
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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