[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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  
0
deon001
Asked:
deon001
  • 4
  • 2
1 Solution
 
Sammy AgeilCommented:
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

0
 
deon001Author Commented:
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
0
 
Sammy AgeilCommented:
This is your code in C#
private void Page_Init(object sender, System.EventArgs e)
{
string ContentPage = "";
ContentPage = Request.QueryString("ContentPage");
if (ContentPage == "") {
 ContentPane.Controls.Add(Page.LoadControl("~/LaborControl/Welcome.ascx"));
} else {
 ContentPane.Controls.Add(Page.LoadControl("~/" + ContentPage));
}
ContentPane.Visible = true;
}
<div class="clsMenuItem">
<A href="Home.aspx?contentpage=Folder1/MyWebUserControl.ascx">Option1</A>

In VS.Net 2005 you can use the DropDown controls just above the editor window to generate the code you need for a Page_Init event since it doesnt do it for you automatically like VS.Net 2003

Good luck
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Sammy AgeilCommented:
this is a great place to convert VB.Net to C# and vice versa
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

0
 
deon001Author Commented:
Thanks again for the help; got it working.
0
 
Sammy AgeilCommented:
You welcome Deon
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now