Solved

How to assign a SiteMapDataSource object to a user control property

Posted on 2012-03-21
4
378 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 500 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 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