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.
Related
I am trying to automate a download function from a broker. I have been able to logon with id and pw, navigate to specific web pages, and select and collect items from the site. I am stumped, however, on how to select an ARIA:Listbox item in an embedded form. All the examples I have seen show windows forms listbox or HTML select lists which is not the way this www site is built.
I have been successful with the c# Selenium findelement By.ID for the listbox required, but the last error said it must be scrolled into view. I'm guessing that the item is not in view because I haven't got the ARIA Listbox click to work to display the list. I've tried clicking on the dropdown arrow, and on the cell itself but the list doesn't show up.
I need some pointers on what to try next.
Thanks
OK - here's some additional info:
I apologize if this doesn't present right - I'm just learning to use the site...
When I use the program code
browser_driver.FindElement(By.Name("OfxDownloadForm:downloadOption")).Click();
I get the message
OpenQA.Selenium.ElementNotInteractableException: 'Element could not be scrolled into view'
The relevant html follows:
<span id="OfxDownloadForm:downloadOption" role="presentation" onfocusjs="removingDuplicateContentFromMenu();;vg.validation.focus(this)" onchangejs="setWarnings('downloadOption');" onblurjs="vg.validation.blur(this)" class="vg-SelOneMenu" compname="selectOneMenu">
<div class="vg-SelOneMenuCont vg-SelOneMenuNoWrap vg-SelOneMenuFocusText vg-SelOneMenuHover" id="OfxDownloadForm:downloadOption_cont" aria-owns="menu-OfxDownloadForm:downloadOption">
<a href="javascript:void(0);" onclick="return false;" class="vg-SelOneMenuTrigger" id="OfxDownloadForm:downloadOption_aTag" role="button" aria-xpanded="false" aria-haspopup="true" aria-controls="menu-OfxDownloadForm:downloadOption" aria-labelledby="downLoadOptionText OfxDownloadForm:downloadOption_text" aria-disabled="false">
If I go after "OfxDownloadForm:downloadOption_aTag" with:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(By.ID("OfxDownloadForm:downloadOption_aTag")));
browser_driver.FindElement(By.ID("OfxDownloadForm:downloadOption_aTag")).Click();
Nothing happens - the popup doesn't occur.
Hope this comes out ok!
After much research and reading, I figured out that I had to do a two step action in the program:
input_element = browser_driver.FindElement(By.Id("OfxDownloadForm:downloadOption_aTag"));
Actions actions = new Actions(browser_driver);
actions.MoveToElement(input_element);
actions.Perform();
input_element.Click();
I believe the FindElement method just located the element, but didn't reposition the mouse into the document on that element. MoveToElement method scrolled down the document and brought the element into the view, and then a click on the same element allowed the drop-down listbox to do its processing. Once I did the find and the move, I was able to select the appropriate dropdown item.
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 did perform investigation and I didn't find good and constructive information to my questions. That is why my question is regarding the control which I would like to extend and render the controls on my own way.I'm working with SharePoint but the SharePoint aspnet control is sealed so I cannot derive from it.
What I have is a menu control which derives from:
System.Web.UI.WebControls.Menu
or
Microsoft.SharePoint.WebControls.AspMenu
I don't see any big difference. And I have the data source / data provider.
SiteMapDataSource dataSource = this.GetDataSource() as SiteMapDataSource;
SiteMapProvider provider = dataSource.Provider;
So I have all the needed elements.
Now the base classe has a lot of different methods which I can override, but I'm not sure how to start with.
Where and how should I create controls to render?
Where do I render those controls?
The contols they exist of html?
<ul>
<li> </li>
...
</ul>
How do I build then a menu based on the provider?
Just a small update to give a full picture:
I do this because I need to render first control not as a link and text but as a image link with image set to a provided url.
Hello you can use extension method on Menu
public static void YourExtension(this Menu control)
{
control.YourPropertyTarget = ....;
}
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>
I have an ASP.NET MVC application and I'm trying to implement tabs which will navigate to different pages. The tabs are implemented as a simple ASCX usercontrol, e.g.
<ul>
<li>Number One</li>
<li class="activePage"><a href="xyz2.html>Number Two</a></li>
<li>Number Three</li>
</ul>
The current page is designed through the "activePage" css class (in above demo code on tab #2).
What is an easy and efficient way to communicate to the ASCX which tab should get the activePage class without having to modify it for each page?
Sample code is highly appreciated.
Would a solution such as using jQuery to highlight the active tab work for you?
You could select the <a> that contains the href attribute that equals the current page, and add a class to the parent <li>.
This is the simplest solution I can think of.
have a look at these two pages:
asp.net mvc and css: Having menu tab stay highlighted on selection
An easy way to set the active tab using controllers and a usercontrol in ASP.NET MVC?