Solved

ASP.NET Dynamic User Control Fire Parent Event in VB

Posted on 2011-03-06
6
701 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

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.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…

738 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