I am just beginning my journey into web development and I have a very basic question, but I am none the less stumped.
I have setup a new ASP.NET Empty Web Application. In this application, I have created a few *.aspx pages and a sitemap called 'Web.sitemap'.
I have placed a SiteMapPath control onto my Master page and, with no further configuration, this detected my Web.sitemap and displays the location of the page on any *.aspx page which derives from the master page.
However, whenever I add a Navigation Menu, this doesn't happen. When I bring up the Menu Tasks dialogue box, I can't select this from the Choose Data Source dropdown, my only option is to choose <New data source...> which brings up the Data Source Configuration Wizard, and from this I can create a new Site Map, however I want to use the already existing one.
How do I go about this?
Thanks
You need to add a SiteMapDataSource and set its SiteMapProvider property to whatever the name of your default provider is in the Web.Config so it would end up like this
<asp:SiteMapDataSource
ID="siteMapDataSource"
SiteMapProvider="ProviderName"
runat="server" />
Then in your Menu control you need to set the DataSourceID to the ID of the SiteMapDataSource you just added
<asp:Menu
ID="uxMenuEcProductCategories"
runat="server"
DataSourceID="siteMapDataSource">
</asp:Menu>
Related
I have a web application with two pages at the moment, The first page the user needs to complete some details, with a button that needs to open the second page with a list of buildings and the user needs to choose one of to populate a list of textboxes in the first form.
My question is, from a button on the first page. (CreateSurvey.aspx) I want to open the second page (Search_Property.aspx)
I have come across syntax like
Search_Property Search = new Search_Property();
Search.open();
But the .open does not exist in this context.
Could someone help me please.
Regards
Rob
In Web forms, you open pages by redirecting to the new page. So, in your button click event, you would use:
Response.Redirect("Search_Property.aspx"); or
Server.Transfer("Search_Property.aspx");
And of course there's the option to modify your button markup to post directly to Search_property.aspx as shown here:
<asp:Button ID="searchButton" runat="server" Text="Search" PostBackUrl="~/Search_Property.aspx" />
If you don't want to navigate to another page and then back again, there are several options. You can create HTML "dialogs" in your CreateSurvey.aspx page and show/hide them as necessary. You can also use an IFRAME on the CreateSurvey.aspx page to display the Search_Property.aspx page and then use some Ajax (HttpXmlRequest) to update the CreateSurvey.aspx page.
I'm a DotNetNuke newbie. Please be gentle. I'm using the "DotNetNuke 6 Compiled Module" template to build my module. I already have View.ascx control in the project and have added another control called test.ascx.
My question is: how do I show different different views in different pages I add the module to. (if that is possible at all)
e.g
Show View.ascx on say the default.aspx page and then on the default2.aspx page show the test.ascx user control?
If this is not possible does it mean I need different visual studio projects for each ascx control. Surely not.
Astro,
Option 1:
You need to go to Host > Extensions > Edit your extesion > Expand Module definition and click on add control.
Here you have to select your ascx control and provide key as any string. Let's say you provided key test, you selected user control and selected control type as view and saved it.
Now from view you can use following code to navigate to the newly added control:
DotNetNuke.Common.Globals.NavigateUrl(TabId,"test","mid="+ModuleID);
This will redirect the page and load your page with test.ascx.
You can use this kind of option when you want to show view.ascx by default and want to switch view when on some action and show test.ascx. Disadvantage here is, when you switch to test.ascx, all other modules added to page will not be visible.
Option 2:
You have to create a new definition in module. For that go to Host > Extensions > Edit Your module > Expand Module Definitoins > Click on add and add new definition. Once definition is added, you can add your test.ascx and view control to the definition without any key.
Once above is done, if you delete and add your module to page again, it will show two modules added in the page. These are two definitions. Look at the blog module definition for example of how multiple definitions works.
This option is used when you want to show multiple view control at the same time from the same module.
I hope this helps. Let me know if you have any more questions.
A little late to the party here, but if I understand you correctly, you want to have a module with different views. To add to Prashant's methods, here are 2 options I often use;
1.) Multiview
<asp:MultiView ID="myMView" runat="server" ActiveViewIndex="0">
<asp:View ID="ViewOne" runat="server">
...Content 1 here...
</asp:View>
<asp:View ID="ViewTwo" runat="server">
...Content 2 here...
</asp:View>
</asp:MultiView>
In code behind you can set the active view based on some condition
if(someCondition)
myMView.ActiveViewIndex = 0;
else
myMView.ActiveViewIndex = 1;
2.)Placeholder. This is my favorite as it allows me to separate each view and its code in its own control. You only need to register one control (the Master control) with DNN. You can have 10s, 100s, 1000s of child controls and they don't need to be registered with DNN as they will be contained inside MasterControl.ascx placeholder.
In the MasterControl.ascx, add
<asp:PlaceHolder ID="myPholder" runat="server"></asp:PlaceHolder>
Follow Prashant's instruction in method 1 and register the MasterControl with DNN. In the code behind, add the following,
string childControl;
switch (condition)
{
case "condition1":
childControl = ControlPath + Child1.ascx";
break;
case "condition2":
childControl = ControlPath + Child2.ascx";
break;
...more conditions...
}
PortalModuleBase objModule = (PortalModuleBase)this.LoadControl(childControl);
if ((objModule != null))
{
myPholder.Controls.Clear();
objModule.ModuleConfiguration = this.ModuleConfiguration;
myPholder.Controls.Add(objModule);
}
Just a different way of doing things. Good luck.
I'm writing a website in Visual Studio Web Developer 2010 (Express edition). I have created a Master file which my content is styled with.
I want to put a right hand menu in my master file, but from the actual website pages, I want to say whether it should show particular menu items. For example, the home page would have a certain set of menu items on the right where as the contact page might have another set.
Should I set it up so that the master file handles true or false as to whether to show certain menu items (default all to false)... or should I handle this from the content pages? ie: call menu functions to draw from there?
You can add a master page declaration to the page, so that you can access it programmatically like so:
<%# MasterType virtualPath="~/MasterPage.master"%>
Put that right under the Page tag on the page you want to enable or disable access from.
Then, in your code behind, you can access the master page methods, one of which can be a method to enable or disable that side menu.
Something like:
Master.MyEnableMenuMethod();
Additionally, you can add that Master Page declaration dynamically, like so:
void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = "~/MasterPage.master";
}
See http://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.85).aspx for more.
The way I've done this sort of thing is by putting some code withing the menu markup as so:
<% if(!HttpContext.Request.Path.Contains("Contact.aspx")) { %>
<li> Contacts</li>
<%}%}>
And so on...
I'm using Visual studio 2005, ASP.NET and C#.
I want to use menu bars which have an active look to them when their respective target page is the one currently showing.
Imagine a user clicks a menu item, navigation to the target page occurs and the menu item they selected is now differing, in say, color to that of the other items in the menu as a means to indicate this is the currently active location.
How might one achieve this?
do you want to create a navigation menu, when the user click on some link the target change to different color?
if so, you can do it with html and css only.
or if you like you can create css class.
then you can check what page you in and change the cssClass property of object in server side .
The best way to sort this is to add a css class to the button/link which changes the style of the item to highlight it. i.e.
<ul>
<li><a id="Url1" href="/Url1" class="selected" runat="server">Item 1</a></li>
<li><a id="Url2" href="/Url2" runat="server">Item 2</a></li>
</ul>
I usually try and to this by detecting it from the url so that if the user goes to the page directly the code can handle that too. It can be done either via ServerSide C# or javascript, but I always implement using server-side code as this will still work if the user has JavaScript disabled.
In VS2008 source view, the left side object dropdown is missing "Server Objects & Events", and "Server Code". I would like to know how to enable these to be visible.
The controls on the page do contain runat="server".
Those items only appear if you are using a single-page model for your code (i.e., html and code are both in the aspx page with no code-behind). If you are using a code-behind file, then you will not get those options while looking at the page's source view.
See the yellow box part way down this page in MSDN.
when you create a new asp page clear the check box for place code in separate file.This ensures that the IDE puts all code within .aspx file .
after do that...
go to :
Tools > options > Text editor >All languages >General >>>> tick the navigation bar check box
.