ASP Menu rendering outside of it's container div - asp.net

I'm preparing to demo my client's system, but all my work thus far has been on my development and test environments and has all gone very smoothly. Setting the system up on a new environment for the demo has - for some reason I can't explain - wrecked the menu.
Basically the menu in the demo environment, while using the exact same code as the other, the menu doesn't render inside of it's container. Screenshots and code to follow:
How it should look
How it does look
I originally wrote the system in Visual Studio 2012, but due to unforeseen limitations with a demo, I had to "port" it all back to 2010. Basically this just involved some copy/paste of the event handlers and such into new files.
Here's the code:
<div class="menu">
<asp:Menu runat="server" ID="mnuLoggedIn" Orientation="Horizontal" RenderingMode="List">
<Items>
<asp:MenuItem Text="Manage Complexes" NavigateUrl="~/Members/Complex.aspx" ToolTip="View, add, edit or delete complexes"></asp:MenuItem>
<asp:MenuItem Text="Manage Units" NavigateUrl="Units.aspx" ToolTip="View, add, edit or delete units"></asp:MenuItem>
<asp:MenuItem Text="Manage Subcontractors" NavigateUrl="Subcontractors.aspx" ToolTip="View, add, edit or delete subcontractors"></asp:MenuItem>
<asp:MenuItem Text="Manage Insurers" NavigateUrl="Insurers.aspx" ToolTip="View, add, edit or delete insurers"></asp:MenuItem>
<asp:MenuItem Text="Manage Insurance Policies" NavigateUrl="Policies.aspx" ToolTip="View, add, edit or delete insurance policies"></asp:MenuItem>
<asp:MenuItem Text="Manage Jobs" NavigateUrl="Jobs.aspx" ToolTip="View, add, edit or delete jobs"></asp:MenuItem>
</Items>
</asp:Menu>
</div>
And the css...
/* MENU
============================================ */
.menu
{
display: block;
height: 30px;
clear: both;
border-radius: 5px 5px 0 0;
background: #121211;
}
.menu ul li a
{
margin-left: 20px;
color: #fff;
line-height: 30px;
}
.menu ul li a:hover
{
color: #85bf25;
border: 0;
}
I feel like maybe I'm relying too much on the asp to handle the menu layout.
I wish I could provide a link to a working test case online, but no hosting that I have access to has support for asp.net. What I have done is to zip up the master page where this menu is, it's content page (which is as yet empty) and the stylesheet for your attention:
http://www.loganyoung.za.net/code/asp-menu-rendering-outside-of-its-container-div.zip
I've run through this with a fine-toothed comb and I just can't figure out what's causing the menu to appear outside of it's container.
Any assistance will be greatly appreciated. Thanks in advance!

Still don't know why this happened, but setting a negative top margin put the menu exactly where I needed it:
.menu
{
display: block;
height: 30px;
clear: both;
border-radius: 5px 5px 0 0;
background: #121211;
}
.menu ul li a
{
margin-top: -20px;
margin-left: 20px;
color: #fff;
line-height: 30px;
}
.menu ul li a:hover
{
color: #85bf25;
border: 0;
}

Related

How to set select box height in asp.net for DropDownCheckBoxes

I am unable to set Select box height for DropDownCheckBoxes in asp.net. I was able to set SelectBoxWidth, DropDownBoxBoxWidth, DropDownBoxBoxHeight.
I even tried adding SelectBoxCssClass but not working. First image is my current output. I am trying to get output as in second image
Any help appreciated
<asp:DropDownCheckBoxes ID="DdlProject" runat="server" OnTextChanged="DdlProject_TextChanged"
AddJQueryReference="true" AutoPostBack="true" CssClass="dd_chk_select" OnSelectedIndexChanged="DdlProject_SelectedIndexChanged" >
<Style SelectBoxWidth="120" DropDownBoxBoxWidth="120" DropDownBoxBoxHeight="120" DropDownBoxCssClass="btn-default dropdown-toggle" SelectBoxCssClass="btn-default dropdown-toggle dd_chk_select"/>
<Texts SelectBoxCaption="Select Project" />
</asp:DropDownCheckBoxes>
.dd_chk_select {
height: 30px;
text-align: center;
border-radius: 5px;
}
in your style try setting the tag as important
.dd_chk_select {
height: 100px !important;
text-align: center;
border-radius: 5px;
}
You said it worked, this means that your height style was being overwritten somewhere.

Control style overridden

I have the following ASP.Net code
...
<div style="width: 40%; float: left; margin-left: 15px">
<b>County:</b>
<asp:ComboBox ID="cboCounty" runat="server" MaxLength="0"
AutoCompleteMode="SuggestAppend" CssClass="EPSCombo">
</asp:ComboBox>
<br />
...
The problem: This div contains many combobox's and they are not showing as expected, they all have EPSCombo class. and when I debug the CSS I find that it is being overridden, here is the output from FireBug
My EPSCombo style is as follows (overriding the default AjaxToolkit CSS)
.EPSCombo .ajax__combobox_inputcontainer .ajax__combobox_textboxcontainer input
{
margin: 0;
border: solid 1px #7F9DB9;
border-right: 0px none;
padding: 1px 0px 0px 5px;
font-size: 13px;
height: 18px;
}
.EPSCombo .ajax__combobox_inputcontainer .ajax__combobox_buttoncontainer button
{
margin: 0;
padding: 0;
background-image: url(../images/windows-arrow.gif);
background-position: top left;
border: 0px none;
height: 21px;
width: 21px;
}
.EPSCombo .ajax__combobox_itemlist
{
border-color: #7F9DB9;
}
And the CSS file containing EPSCombo is the last one included in the Master page.
Question: It might had been a while since I did web development, but if I decide the CSS class for a control shouldnt that have the highest priority and should override everything else, correct? If so, then why is my combobox style (Height, Width, margin, and padding) is being overridden?? I dont have any other style class that set the height and width for those values shown in Firebug.
Update after Loki's answer I thought I should add this, adding !important to these attributes would solve the problem, but I want to get to the root cause of this and see where things went wrong.
Your ComboBox may be inheriting it's styling from the <div> it is contained in, or from a div higher than that. Since you have not specified a 'class' or 'ID' attribute for the div that it is contained within, that div may be retrieving style from your CSS file if you have something like:
div
{
height: 21px;
margin: 0px;
padding: 0px;
width: 21px;
}
To force your ComboBox to take independent styling though you may use the asp style attribute like so:
<asp:ComboBox ID="cboCounty" runat="server" MaxLength="0"
AutoCompleteMode="SuggestAppend" style="margin: 0;padding: 0;height: 21px;width: 21px;">
</asp:ComboBox>
That should be the highest priority over any other styling that may be interfering in your application. Although considered improper programming practice it may help you narrow down the issue.
Cheers, Eric
EDIT I should also mention that your CSS code is interpreted in order from the most specific to least specific tag definitions. Ex, div.menu is more specific than div, this may be occurring somewhere else in your style-sheet.
This is also a good article to look at describing inheritance. Hope this helps!
A quick fix - add !important flags to your stylesheet. They'll have higher priority over everything else, unless there are other flags defining the very same property of the very same element

asp.net css issue after deployment

I am experiencing a very strange issue. I have developped an application locally and everything works file. But on the production server i have several problems. The most annoying is the Navigation Menu that changes from horizontal to vertical after login.
site.Master
<asp:Menu ID="NavigationMenu"
runat="server"
cssclass="menu"
EnableViewState="false"
IncludeStyleBlock="false"
Orientation="Horizontal"
StaticDisplayLevels="1"
staticsubmenuindent="10"
target="_blank"
MaximumDynamicDisplayLevels="1"
Enabled="False"
Visible="False">
Site.css
/* TAB MENU
----------------------------------------------------------*/
div.hideSkiplink
{
background-color:#3a4f63;
width:20%;
z-index:9999;
}
div.menu
{
padding: 4px 0px 4px 8px;
z-index:9999;
}
div.menu ul
{
list-style: none;
margin: 0px;
padding: 0px;
width: 20%;
z-index:9999;
}
div.menu ul li a, div.menu ul li a:visited
{
background-color: #465c71;
border: 1px #4e667d solid;
color: #dde4ec;
display: block;
line-height: 1.35em;
padding: 4px 20px;
text-decoration: none;
white-space: nowrap;
z-index:9999;
}
div.menu ul li a:hover
{
background-color: #bfcbd6;
color: #465c71;
text-decoration: none;
z-index:9999;
}
div.menu ul li a:active
{
background-color: #465c71;
color: #cfdbe6;
text-decoration: none;
z-index:9999;
}
The css i use is the default.
I searched the net but no solution is proposed. Is it a server issue?Is it my code?
There is this thread with the exact problem. http://forums.asp.net/t/1762140.aspx/1?Odd+menu+problem+after+deployment , which doesnt propose a solution for the problem
Thanks
In all likelihood, the javascript which adds the class is not running on the page
There could be a number of reasons
It wasn't deployed properly.
The path is incorrect on the live server (are you in a different directory layout - eg /JavaScript/ instead of /myapp/JavaScript/?
NoScript or another addon is blocking javascript (browser-specific)
Something in the JS breaks on live and prevents execution before it gets to the relevant code
To track the problem down - Go to the net tab in firefbug and look at the javascript - does it all load with an HTTP 200 (Ok) ? Any 404/500s?
Try disabling all addons in your browser / use different browsers - same problem?
Open up the Script tab in firebug or the JavaScript console (CTRL Shift K in Firefox)
Reload your page and see if any errors/warnings appear.
Edit your answer with the results of the above and we'll see what we can do.
EDIT:
With regards to the 403/Forbidden - WebResource.axd is where the .Net Control-specific JS lives so this is almost certainly your problem. To make it more fun, .axd's aren't usually real files - they're HTTP handling extensions - see here and here for more information. Check your web.config - did the appropriate handlers get set in Live? It should be something like...
<add path="WebResource.axd"
verb="GET"
type="System.Web.Handlers.AssemblyResourceLoader"
validate="True" />
If you've got an entry like that, can you edit your question to include it exactly? If not, try adding it
Possible fix here
Does the live server have the same version of the framework/controls installed as your development machine - Make sure it has!
Another thing to be aware of is that if you manually deploy a website, the files are usually owned by you, not the webserver - This can sometimes mean the webserver can't read the website to serve it. I doubt that's the problem here but it's something to be aware of in future. (To check, the website user is specified on the application pool for the site in IIS Manager).

Problem with Internet Explorer layout for a drop down menu

I have a drop down menu that I have styled using CSS and a Jquery plugin named: Selectbox. http://www.devirtuoso.com/2009/08/styling-drop-down-boxes-with-jquery/
Everything is working great and looks perfect in Firefox, Chrome, and Safari. But for some reason when I click the drop down box in Internet Explorer the drop down floats all the way to the right and not directly beneath the drop down. I have only been coding 3 months so it could be a really stupid mistake but I can't seem to figure it out. Any help would be appreciated.
Here is the HTML:
<div class="foldersoption">
<select name="Items" id="Items">
<option value="option1">My Items</option>
<option value="option2">Shoes</option>
<option value="option3">Birthday Ideas</option>
</select>
</div>
Here is the CSS:
.foldersoption{
float: left;
margin-left: 25px;
}
div.selectbox-wrapper ul li {
border: 1px solid #FFFFFF;
cursor: pointer;
display: block;
font-size: 12px;
list-style-type: none;
padding: 5px;
text-align: left;
width: 243px;
}
.selectbox {
cursor: pointer;
display: block;
float: left;
font-size: 15px;
height: 25px;
padding-left: 5px;
text-align: left;
width: 250px;
}
Can you help please?
Apply zoom and position relative to the foldersoption element, and other elements as needed. For example:
.foldersoption {
zoom: 1;
position: relative;
}
This will force IE to treat it like the other browsers do. IE doesn't handle floating very well - you have to give it some additional configuration & constraints in order for it to work properly.
Edit: Based on the screenshots, IE is complaining about security issues - is there a chance it is blocking certain scripts from loading as well? Try disabling or reducing the security in IE and see if the menu drops.
Edit #2: Actually that plugin you used is old and does not appear to be well tested or maintained. Can I suggest an alternative?
http://plugins.jquery.com/project/jQuerySelectBox
You can see an example here: http://labs.abeautifulsite.net/projects/js/jquery/selectBox/
I tested it in IE7 and it seems to work ok. Seems extremely simple to set up, and to change the appearance you only need to change or override the default CSS styles.

Styling checkboxes, radio buttons and dropdowns

How can I style HTML checkboxes, radio buttons and dropdowns? Or can I?
I'd like to use an image for checkboxes or radiobuttons, and the same for lists - the dropdown arrow doesn't look nice most of the time.
see this 2 links for jQuery Plugins for Styling Checkbox & Radio Buttons:
http://line25.com/articles/jquery-plugins-for-styling-checkbox-radio-buttons
http://www.queness.com/post/204/25-jquery-plugins-that-enhance-and-beautify-html-form-elements
Short answer: You can't do it nicely and consistently.
The answer you might want to hear, depending on your situation: Use jQuery or something similar, which will give you plenty of plugins to choose from.
These two are some of the better ones, as it will let you style just about all of the different controls.
You certainly can,
Checkboxes and Radio buttons are easy to customize with just css (no js).
The implementation (already mentioned by KunalB above) involves hiding the input and using the label (with the before pseudo element for the custom image) to trigger the input
Dropdowns on the other hand are a lot more difficult and to date there's no 100% pure-css + cross-browser solution... (Here's my S.O. answer for dropdowns)
LIVE DEMO for all 3: Radio buttons,Checkboxes and Dropdowns.
Custom Checkbox
h2 {
font-weight: bold;
margin: 20px 0 5px;
}
li {
margin: 0.5em 0;
}
/*#region checkbox */
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]~label {
display: inline;
font-size: 18px;
}
input[type="checkbox"]~label:before {
content: '';
border-radius: 0.2em;
border: 1px solid #333;
display: inline-block;
cursor: pointer;
vertical-align: middle;
margin-right: 0.5em;
width: 32px;
height: 32px;
display: inline-flex;
justify-content: center;
align-items: center;
}
input[type="checkbox"]:checked~label:before {
content: '✓';
}
<h2>Custom Checkbox</h2>
<div>
<input checked="checked" id="RememberMe" name="RememberMe" type="checkbox">
<label for="RememberMe">Remember me</label>
</div>
Custom Radio Button
input[type="radio"] {
display: none;
}
input[type="radio"]+label {
display: inline;
font-size: 18px;
}
input[type="radio"]+label:before {
content: '';
display: inline-block;
width: 32px;
height: 32px;
border: 1px solid #222;
border-radius: 50%;
vertical-align: middle;
margin-right: 0.5em;
}
input[type="radio"]:checked+label:before {
content: '';
box-shadow: inset 0 0 0 0.6em white, inset 0 0 0 1em #333;
}
h2 {
font-weight: bold;
margin: 20px 0 5px;
}
ul {
list-style: none;
}
li {
margin: 0.5em 0;
}
<h2>Custom Radio Button</h2>
<ul>
<li>
<input type="radio" id="radio1" name="radios" checked />
<label for="radio1">Apples</label>
</li>
<li>
<input type="radio" id="radio2" name="radios" />
<label for="radio2">Pineapples </label>
</li>
</ul>
Custom Dropdown
select {
width: 150px;
padding: 5px 35px 5px 5px;
font-size: 16px;
border: 1px solid #CCC;
height: 34px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: url(http://www.stackoverflow.com/favicon.ico) 96% / 15% no-repeat #EEE;
}
/* CAUTION: Internet Explorer hackery ahead */
select::-ms-expand {
display: none;
/* Remove default arrow in Internet Explorer 10 and 11 */
}
/* Target Internet Explorer 9 to undo the custom arrow */
#media screen and (min-width:0\0) {
select {
background: none\9;
padding: 5px\9;
}
}
<h2>Custom Dropdown</h2>
<select>
<option>Apples</option>
<option selected>Pineapples</option>
<option>Chocklate</option>
<option>Pancakes</option>
</select>
This guy pretty much has all the styling you can put on form controls, but it's not consistent across browsers. You are going to have to go custom. Use a custom image for the checkbox, then change it's source to get the clicked version (and vice versa). The select menu might be a little trickier. I hope there's a jQuery plugin out there that can help you!
I believe CSS 3 will allow you to style those elements, but for now it isn't directly possible.
See this question: CSS checkbox input styling
You can style form elements, but it is difficult (impossible?) to get a consistent style across browsers and operating systems with a pure CSS approach. Some script manipulation of styles would also be required.
This is a very good article that discusses the options and issues: Styling form controls
Listamatic has a great collection of CSS list styles.
You can't put an image as a checkbox, but you can always build your own checkbox :D.
Put a hidden field and an image, add an "onclick" event over the image. When the onclick is fired check the status of the hidden field, change the image according to the status and save the status of the checkbox in your hidden field.
You should check for custom javascript libraries. One of my favorities is http://www.dojotoolkit.org/
Most likely you won't be able to, it is very difficult. Personally, I would just stay away from that.
You might find my post useful: http://kunal-b.in/2011/07/css-for-attractive-checkboxes-and-radio-buttons/.
The basic idea is to hide the form ele­ment (checkbox/radio but­ton) and style the label instead using CSS. Thanks to the :checked selec­tor, it’s pos­si­ble to dis­tin­guish between the two label states by assign­ing styles to label and input:checked + label assum­ing that the label fol­lows the checkbox/radio but­ton in your html code. Using a for attribute in the code makes the com­plete label click-able, mod­i­fy­ing the state of the asso­ci­ated element.
Recently i come across amazing WTF, forms? from a creator of Bootstrap Mark otto. It has great styles for
Checkbox
Radio button
Select
Progress bar
File Browser
Checkout http://wtfforms.com/
You don't need any library for the same. You can do it on your own with pure CSS, and just a line of javascript/jquery.
You don't need any libraries for these.
You can put li'l logic and you can roll on your own.
A line of javascript/jquery, and everything CSS.
Guide here-
https://github.com/scazzy/CSS-FORM-UI

Resources