Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to assign a SiteMapDataSource object to a user control property

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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