newbie: Problems in the code... again

J

Jeff

hey

asp.net 2.0

On my webpage have I placed a LoginView (named lvSidebar). On this
loginview's loggedInTemplate I placed a menu (mnuSidebar) and the datasource
to the menu is SiteMapDataSource1.

My Problem is that I cannot access the SiteMapDataSource1 object from the
code:
lvSidebar.LoggedInTemplate.SiteMapDataSource.StartingNodeUrl =
"Default.aspx";
don't compile:
System.Web.UI.ITemplate' does not contain a definition for
'SiteMapDataSource1'

Any ideas what I should do to solve this?

Jeff
 
G

Guest

The LoggedInTemplate property of the LoginView control does not have a
property called SiteMapDataSource which is what is causing the error. If you
want to prograamatically set the StratingNodeURL property of
SiteMapDataSource1 simply use the following code

SiteMapDataSource1.StartingNodeUrl = "Default.aspx";

The LoginView has nothing to do with it.
 
J

Jeff

hmm when I in the code start to type "SiteM" the SiteMapDataSource1 isn't
shown in the type-ahead list... this happens if I try to access the
SiteMapDataSource like this SiteMapDataSource1.StartingNodeUrl =
"Default.aspx"; or
lvSidebar.LoggedInTemplate.SiteMapDataSource.StartingNodeUrl

Another thing is that my webpage has 2 SiteMapDataSource1 controls (yes they
have the same name, but they exist in their own LoginView, lvSidebar and
lvMenu).

Any more suggestions?

Jeff
 
G

Guest

If you want to access a control that is within another control you need to
use the following syntax:

ParentControl.FindControl("ChildControlID")

This will return a reference to the child control. You will also need to
cast it to the correct type.

In your case you would use something like the below C# code

SiteMapDataSource MySiteMapDataSource = (SiteMapDataSource)
lvSidebar.FindControl("SiteMapDataSource1");
MySiteMapDataSource.StartingNodeUrl = "Default.aspx";
 
J

Jeff

thanks, it solved my problem


clickon said:
If you want to access a control that is within another control you need to
use the following syntax:

ParentControl.FindControl("ChildControlID")

This will return a reference to the child control. You will also need to
cast it to the correct type.

In your case you would use something like the below C# code

SiteMapDataSource MySiteMapDataSource = (SiteMapDataSource)
lvSidebar.FindControl("SiteMapDataSource1");
MySiteMapDataSource.StartingNodeUrl = "Default.aspx";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top