Link to home
Start Free TrialLog in
Avatar of deon001
deon001

asked on

Opening UserControl from menu ASP.Net 2005

Hi Experts

I’m new to ASP 2.0 .Net 2005 and have setup a default.aspx page with a menu control.

<Items>
    <asp:MenuItem Text="MenuOption1" Value="AAA">
    <asp:MenuItem Text="Option A1" Value="A1"></asp:MenuItem>
    <asp:MenuItem Text="Option A2" Value="A2"></asp:MenuItem>
</Items>

When I click on my menu Items(“Option A1”) I want to load a WebUserControl.ascx into a table on the default.aspx page.

How do I then open(call) the user control to open-up inside the table on the default.aspx page? This should be something very simple to do…

Thanks for the help!
Deon  
Avatar of Sammy
Sammy
Flag of Canada image

generally if you want to deal with a usercontrol you use findcontrol property sending it a string containing the control's ID then you can do whatever you need to do with the control

findcontrol method is discussed here
http://www.odetocode.com/Articles/116.aspx

Good luck

Avatar of deon001
deon001

ASKER

Hi Sammy, thanks for the quick response.

I have done this previously in .NET 2003 VB and am now moving to ASP C# 2005, and am battling to get the same ting going.

How I did it in VB:

Protected WithEvents ContentPane As System.Web.UI.HtmlControls.HtmlTableCell

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
       
   InitializeComponent()

   Dim ContentPage As String = ""
   ContentPage = Request.QueryString("ContentPage")

   If ContentPage = "" Then
      ContentPane.Controls.Add(Page.LoadControl("~/LaborControl/Welcome.ascx"))
   Else
      ContentPane.Controls.Add(Page.LoadControl("~/" & ContentPage))
   End If
   ContentPane.Visible = True
End Sub

Then I just opened my controls like this:

<div class="clsMenuItem">
<A href="Home.aspx?contentpage=Folder1/MyWebUserControl.ascx">Option1</A>


Im very new at this so thanks for the help and patients
Deon
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

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
this is a great place to convert VB.Net to C# and vice versa
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

Avatar of deon001

ASKER

Thanks again for the help; got it working.
You welcome Deon