Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Load user control dynamically

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??
ASKER CERTIFIED SOLUTION
Avatar of RishadanPort
RishadanPort

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RishadanPort
RishadanPort

Oh and, once you do this, you can simply do:

this.XYZ_ASPX_PAGE.refreshSideMenu();

to refresh the Side Menu
Avatar of Camillia

ASKER

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)
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
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...
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
not sure what you mean...can u give an example...

Also...can this be done with event handeling...do i need an event handler???
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
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

let me see, thanks .