Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to assign a SiteMapDataSource object to a user control property

Posted on 2012-03-21
4
Medium Priority
?
390 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

609 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