Solved

How to assign a SiteMapDataSource object to a user control property

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now