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
Solved

Load user control dynamically

Posted on 2008-10-02
10
1,089 Views
Last Modified: 2012-05-05
I have a master page and a user control. User Control is resgistered on xyz.aspx page. URL rewriting loads xyz.aspx page which in turn loads the UC which shows up on the page/masterpage.

UC builds a side menu.
I added 2 links to my master page. When clicking..i want to call the routine inside the usercontrol to refresh the side menu. Anyway to do this??
0
Comment
Question by:Camillia
  • 6
  • 4
10 Comments
 
LVL 6

Accepted Solution

by:
RishadanPort earned 500 total points
ID: 22628132
First I want to say that I do not know much about "aspx"

I do however have a lot of experience with C# UserControls.

In C# I would simply wrap a routine in a class that inherits a UserControl, and modify the designing like I want it. Here is an example of a class UserControl

public class XYZ_ASPX_PAGE : UserControl
{
   public XYZ_ASPX_PAGE(){
      InitializeComponent();
   }

   public void refreshSideMenu(){
      ....
   }
}


Outside this class I would simply do something like this:

XYZ_ASPX_PAGE page = new XYZ_ASPX_PAGE();

and to add the page to my Main Page, I would do this:

this.masterPage.Controls.Add(page);


I hope this helps
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22628153
Oh and, once you do this, you can simply do:

this.XYZ_ASPX_PAGE.refreshSideMenu();

to refresh the Side Menu
0
 
LVL 7

Author Comment

by:Camillia
ID: 22628327
No, doesnt make sense to me.

1.I have the linkbuttons on a Masterpage:
public partial class MasterPages_Universal : System.Web.UI.MasterPage

So i cant inherit from the UserControl

2. That "refreshsidemenu" is supposed to be in the userContol..right?

3. I did this in click event of the linkbuttons:
   Control FeaturedProductUserControl = LoadControl("~/Controls/ProductFilter.ascx");
  Controls.Add(FeaturedProductUserControl);

This calls my userControl but it doesnt call the "refreshsidemenu"  routine. Anyway to do that?

4. Do you know how I can refresh the entire page when the linkbutton is clicked (maybe this would be easier than loading ONE usercontrol..load the entire page instead of one user control)
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 6

Expert Comment

by:RishadanPort
ID: 22628444
I see what your saying now, MasterPage's Control property can not add in System.Windows.Forms.UserControls... What it does add in is Web.UI.Control. Let me research this topic for a while
0
 
LVL 7

Author Comment

by:Camillia
ID: 22628496
there has to be somehow dynamically calling this:

I made the UC rotuine public..i tried this:
 Control FeaturedProductUserControl = LoadControl("~/Controls/ProductFilter.ascx");
            Controls.Add(FeaturedProductUserControl);
  FeaturedProductUserControl.<i dont see the rotuine here>

*** I thought about reloading the entire page but there are so many user controls and pieces to this and they're all separate...
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22628513
Well you can't see the routine since you are dealing with the Object Control.

You need to type cast it to a higher level object in order to see the routines
0
 
LVL 7

Author Comment

by:Camillia
ID: 22628530
not sure what you mean...can u give an example...

Also...can this be done with event handeling...do i need an event handler???
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22628617
What my book says on this is the following:

1. You need to create a wrapper class that inherits System.Web.UI.Control
-->Here you provide properties, methods, and events.
2. You need to Override the Renderer Method
-->"Each control must implement this method to generate the HTML that represents the control to the browser. Note that the render method is not called directly; instead, a call is made to RenderControl, which then invokes Render. For controls that contain child controls, the RenderChildren method is available."
3. Use HtmlTextWriter object to generate the HTML Code


I am not sure if this helps you... Sorry I am trying my best
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22628679
Here is the example that my book uses:
//(1) In herit from the System.Web.UI.Control Class
public class CompanyLogo : System.Web.UI
{
   ... List properties and methods here ...
 
   //(2) Override the Render Method
   protected override void Render(HtmlTextWriter output)
   {
      //(3) Use the HtmlTextWriter to emit html to the browser
   }
}

Open in new window

0
 
LVL 7

Author Comment

by:Camillia
ID: 22629578
let me see, thanks .
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Video Player 12 28
localhost: This site can’t be reached  localhost refused to connect. 2 214
List<PaisEntity> - show some 1 28
Can I command line build a C# application? 6 40
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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