?
Solved

How to assign a SiteMapDataSource object to a user control property

Posted on 2012-03-21
4
Medium Priority
?
381 Views
Last Modified: 2012-06-21
I have the following user control:

public partial class UserControlLeftMenu : System.Web.UI.UserControl
{
    private SiteMapDataSource _siteMapDataSrc;

    public SiteMapDataSource DataSource
    {
        get { return _siteMapDataSrc; }
        set { _siteMapDataSrc = value; }
    }

  }

How do I assign the property on an .aspx page?

...
<%@ Register src="UserControlLeftMenu.ascx" tagname="UserControlLeftMenu" tagprefix="bvt" %>
...
<asp:SiteMapDataSource ID="WebSiteMapDataSource" runat="server" />
...

Neither of these work, both produce compile errors:
<bvt:UserControlLeftMenu ID="UserControlLeftMenu1" runat="server" DataSource=WebSiteMapDataSource/>
<bvt:UserControlLeftMenu ID="UserControlLeftMenu1" runat="server" DataSource="WebSiteMapDataSource"/>
0
Comment
Question by:elcbruce
[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
4 Comments
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 2000 total points
ID: 37748133
What you need to remember is that in its current form you are actually passing in the string "WebSiteMapDataSource", not the control itseld.

 You have 2 options to get this working :

1) Programatically assign the datasource in the codebehind:

UserControlLeftMenu1.DataSource = WebSiteMapDataSource

2) Change the type of your parameter to String (and for the sake of good practice rename it DataSourceID), then in your code use a recursive FindControl on the usercontrol's Page  property using that string value to find the datasource
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 37748156
For SiteMap alone why do you required a seperate user control?

http://www.c-sharpcorner.com/uploadfile/raj1979/working-with-sitemapdatasource-control-in-Asp-Net-3-5/ could be useful for you.
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37748706
in Code behind page ,you can write

UserControlLeftMenu1.DataSource = WebSiteMapDataSource
0
 

Author Closing Comment

by:elcbruce
ID: 37756630
Thanks for the prompt response.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 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