Solved

ASP.NET Dynamic User Control Fire Parent Event in VB

Posted on 2011-03-06
6
699 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…

790 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