Asp.net menu selected item - asp.net

I've been struggling with this asp.net Menu control problem for days and it's driving me crazy. Here the code:
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" CssClass="hrMainMenu" DynamicHorizontalOffset="1" >
<DynamicHoverStyle ForeColor="White" Font-Bold="True" />
<DynamicMenuItemStyle ForeColor="White" />
<DynamicMenuStyle Width="97px" HorizontalPadding="1px" />
<DynamicSelectedStyle ForeColor="White" />
<DynamicItemTemplate>
<div class="dinamicMenuItemTemplate">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Text") %>' EnableTheming="True"></asp:Label>
</div>
</DynamicItemTemplate>
<StaticMenuItemStyle ForeColor="White" CssClass="StaticMenuItemStyle" />
<StaticMenuStyle HorizontalPadding="10px" CssClass="StaticMenuStyle" />
<StaticSelectedStyle CssClass="staticMenuItemTemplateSelected" ForeColor="Red" />
<StaticItemTemplate>
<div class="staticMenuItemTemplate">
<div class="innerMenuElement">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Text") %>'></asp:Label></div>
</div>
</StaticItemTemplate>
</asp:Menu>
Now this is my css:
.staticMenuItemTemplate
{
background-position: left;
background-image: url('../../images/mainLayout/menuDefault.png');
background-repeat: no-repeat;
width: 100px;
text-align: center;
height: 25px;
position: relative;
top: 0px;
left: 0px;
}
.staticMenuItemTemplate:hover
{
background-image: url('../../images/mainLayout/menuHover.png');
background-repeat: no-repeat;
background-position: left;
font-weight: bold;
}
.staticMenuItemTemplateSelected
{
background-image: url('../../images/mainLayout/menuSelected.png') !important;
background-repeat: no-repeat !important;
background-position: left !important;
color: #FF00FF !important;
}
I want to display a different image when the menu item has been selected (menuSelected.png) but whilst the class staticMenuItemTemplate:hover seems to work and indeed the image changes, the class staticMenuItemTemplateSelected doesn't. Only the text gets pink as stated but the image won't change.
Thanks for your help.

I think the problem has to do with how the HTML renders for this control. In my tests, I end up with something like:
<td>
<a class="... staticMenuItemTemplateSelected ..." ...>
<div class="staticMenuItemTemplate">
<span>Menu text here</span>
</div>
</a>
</td>
So you can see that the <a> tag is getting the staticMenuItemTemplateSelected applied, but the inner <div> is getting the staticMenuItemTemplate class which ends up overriding the staticMenuItemTemplateSelected style since it is more specific.
If you change your declaration of .staticMenuItemTemplateSelected to
.staticMenuItemTemplateSelected .staticMenuItemTemplate
{
background-image: url('../../images/mainLayout/menuSelected.png') !important;
background-repeat: no-repeat !important;
background-position: left !important;
color: #FF00FF !important;
}
you will make that style more specific than the style for .staticMenuItemTemplate and it should work.
FireBug with FireFox is a great tool for investigating CSS weirdness issues.

Related

Center align text in ASP.net menu

New to asp.net and I am trying to center the hover portion of my menu control but for the life of me I cannot figure it out.
Here is my code:
<aside>
<nav>
<asp:Menu ID="Menu" runat="server" DataSourceID="SiteMapDataSource1" DynamicEnableDefaultPopOutImage="False" Orientation="Horizontal"
RenderingMode="Table" backcolor="#CB4154" ForeColor="white" Font-Bold="True" >
<StaticMenuItemStyle HorizontalPadding="8px" VerticalPadding="2px" />
<StaticMenuStyle height="25px" Width="800px" />
<StaticSelectedStyle HorizontalPadding="8px" VerticalPadding="2px" />
<StaticHoverStyle Font-Bold="True" height="75%" width="50%" backcolor="#00B7EB" ForeColor="White" CssClass="StaticHoverStyle"/>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
</nav>
</aside>
And the CSS:
#Menu {
text-align: center;
margin-right:auto;
margin-left: auto;
}
.StaticHoverStyle {
text-align: center;
}
Any input on what I am doing wrong would be appreciated.
make it absolute and add right and left tags
#Menu {
position:absolute;
text-align: center;
margin-right:auto;
margin-left: auto;
right:0px;
left:0px; }
}
.StaticHoverStyle {
text-align: center;
}
i just had a quick look at mine (been a while) and it looks like i put text-align in a wrapping div. what happens it you move your text-align to the nav element? (move the data source out, for clarity.)

Modal popup border disappears when css background applied

I am using the Ajax Modal Popup Extender to display a panel as a modal popup. I've applied a CSS class to the panel and everything displays fine. However, when I add the BackgroundCssClass property to my popup extender, the border on my panel does not show up. The modal background displays properly and everything else in the panel remains the same, but I can't get the border to display. What might be causing this?
**CSS**
.PopupPanel
{
width: 75%;
height: 55%;
text-align: center;
padding: 5px;
overflow: auto;
border-style: solid;
border-width: 8px;
border-color: #0055A5;
background-color: White;
}
.ModalBackground
{
background-color: rgba(170,170,174,0.5);
}
**ASPX**
<asp:Panel ID="InputPanel" runat="server" CssClass="PopupPanel">
<asp:Label ID="HeaderLabel" runat="server"
Text="[text here]"
Font-Size="Large"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="85%"
Height="65%" Wrap="False"></asp:TextBox>
<br />
<asp:Button ID="okButton" runat="server" Text="Submit"
CssClass="genericButton" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel"
CssClass="genericButton" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
PopupControlID="InputPanel" TargetControlID="PasteButton"
BackgroundCssClass="ModalBackground" PopupDragHandleControlID="HeaderLabel">
</ajaxToolkit:ModalPopupExtender>

How can i place Gridview center of div or panel.?

Hello!
Can anyone tell me how can I place any Gridview in center in Div or panel? I have applied following CSS but its does not working:
<asp:Panel ID="pnlGrid" CssClass="panel" runat="server">
<div style="text-align:center">
<asp:GridView ID="grdReqApproval" runat="server" AutoGenerateColumns="false" CssClass="SimpleGrid">
<Columns>
<asp:BoundField DataField="Approved By" HeaderText="Approved By" />
<asp:BoundField DataField="User Name" HeaderText="User Name" />
<asp:BoundField DataField="Approval Time" HeaderText="Approvel Time" />
</Columns>
</asp:GridView>
</div>
</asp:Panel>
.panel
{
width: 330px;
padding: 10px;
min-height: 20px;
border: 1px solid #dcdcdc;
margin-left:auto;
margin-right:auto;
}
HorizontalAlign property of Gridview can solve your problem
<asp:Panel ID="pID" runat="server">
<div>
<asp:GridView ID="gvID" runat="server" AutoGenerateColumns="false"
HorizontalAlign="Center">
<Columns>
...
...
</Columns>
</asp:GridView>
</div>
Check this is working for me , Ultimatly gridview get converted to table so the apply following stylesheet to your gridview which i applied to table
CSS
.centered-table {
margin-left: auto;
margin-right: auto;
}
HTML
<div>
<table class="centered-table" border="1">
<tr><td>Pekin</td> <td>Illinois</td></tr>
<tr><td>San Jose</td><td>California</td></tr>
</table>
</div>
JsFiddle Demo
Slight case of thread necromancy, but I was having the same problem and managed to fix it by aligning the code block rather than the gridview itself.
Basically I set the width of the element to 40%, and left to 30% (which means right is also 30%, because maths) and that positions the whole lot, text, grid and all into the middle of the page.
The css looks roughly like this
GridExample
{
position:absolute;
left:30%;
width:40%;
padding:0;
margin:0;
}
on your div text-align: center
as you see here, your class works. Just be sure its parent container is wider so it can center
http://jsfiddle.net/C7ybw/
#container{
width:800px;
border:1px solid #000;
}
.div_text_center {
text-align: center;
margin-left: auto;
margin-right: auto;
}
<div class="div_text_center">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" HorizontalAlign="Center">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>

Fieldset padding in IE8

I am pretty new to web work. I apologize if this question is trivial or overkilled. I did some searching for fieldset padding, but didn't see anything specific to this.
Here is what my window looks like in Chrome vs IE8.
Chrome: http://i.stack.imgur.com/rH7w0.png
IE8: http://i.stack.imgur.com/6v6kZ.png
As you can see, all of the padding has been completely thrown away.
<fieldset>
<legend>Refresh Settings</legend>
<table>
<tr>
<td class="AutoRefreshEnabled">
Auto-Refresh Enabled:</td>
<td class="AutoRefreshCheckbox">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" />
</td>
<td class="AutoRefreshNumericTextbox">
<telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server"
Label="Auto-Refresh Interval (Minutes):" MaxValue="60" MinValue="0"
ShowSpinButtons="True" Value="0" Width="225px" Enabled="False"
LabelCssClass="riLabel LabelDisabled">
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Tab Settings</legend>
<div>
<div class="FloatLeft">
<telerik:RadListBox ID="RadListBox1" runat="server" AllowDelete="True" AllowReorder="True"
EnableDragAndDrop="True" Skin="Web20" Height="95px"
onclientitemdoubleclicked="OnClientItemDoubleClicked"
onclientselectedindexchanged="OnClientSelectedIndexChanged"
Width="150px" AutoPostBack="True" AutoPostBackOnReorder="True"
onreordering="RadListBox1_Reordering" onclientload="OnClientLoad">
</telerik:RadListBox>
</div>
<div class="FloatRight">
<telerik:RadTextBox ID="RadTextBox1" Runat="server" EmptyMessage="Enter tab name" Skin="Web20" Width="150px">
</telerik:RadTextBox>
<div class="TabButton">
<telerik:RadButton ID="RadButton1" runat="server" onclick="RadButton1_Click" Skin="Web20" Text="Add Tab"
onclientclicked="OnButtonClicked">
</telerik:RadButton>
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Tab Cycle Settings</legend>
<table>
<tr>
<td class="AutoCycleEnabled">
Auto-Cycle Enabled:</td>
<td class="AutoCycleCheckbox">
<asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" />
</td>
<td class="AutoCycleNumericTextbox">
<telerik:RadNumericTextBox ID="RadNumericTextBox2" Runat="server"
Label="Auto-Cycle Interval (Minutes):" MaxValue="60" MinValue="0"
ShowSpinButtons="True" Value="0" Width="225px" Enabled="False"
LabelCssClass="riLabel LabelDisabled">
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
</td>
</tr>
</table>
</fieldset>
<div class="BottomButtons">
<telerik:RadButton ID="RadButton2" runat="server" Skin="Web20" Text="Apply" OnClientClicked="CloseAndSave" >
</telerik:RadButton>
<telerik:RadButton ID="RadButton3" runat="server" Skin="Web20" Text="Cancel" OnClientClicked="CloseAndCancel" >
</telerik:RadButton>
</div>
body
{
font-size: 12px;
font-family: "segoe ui",arial,sans-serif;
}
.LabelEnabled
{
color: Black !important;
}
.LabelDisabled
{
color: Gray !important;
}
.riTextBox
{
color: Black !important;
}
.AutoRefreshEnabled
{
width: 123px;
}
.AutoRefreshCheckbox
{
width: 20px;
}
.AutoRefreshNumericTextbox
{
width: 32px;
}
.AutoCycleEnabled
{
width: 123px;
}
.AutoCycleCheckbox
{
width: 20px;
}
.AutoCycleNumericTextbox
{
width: 32px;
}
.TimeframeRestricted
{
width: 314px;
}
.DataPointsShown
{
width: 314px;
}
.TimeframeCheckbox
{
width: 40px;
}
.DatapointsCheckbox
{
width: 40px;
}
.TimeframeDateTimePickers
{
width: 150px;
}
.FloatLeft
{
float: left;
}
.FloatRight
{
float: right;
padding-right: 55px;
}
.TabButton
{
text-align: left;
padding-top: 2px;
}
.BottomButtons
{
position: absolute;
left: 134px;
bottom: 13px;
}
Does anyone with more web development experience than I have an easy explanation for this issue? It would be much appreciated.
Thanks for your time.
it is an IE thing, and legend is the culprit a simpler fiddle with some "garish" coloring and forced padding shows the only fieldset that actually contains itself is the one without a legend - http://jsfiddle.net/eDtDh/
I have never used legend and I forgot why but I think this is the reason it's the same in IE7/6 etc.... you could build in your own legend via a heading element and relatively position it to look similar to a legend

asp:button disappears in IE7, but stays in IE8. Why?

I have the following html which is display correctly in IE8. Below is the html and the css for grey_btn_75. Any idea why this would be happening?
<div style="float: left; width: 70px; margin-right: 25px; padding-top: 60px;
margin-left: 25px">
<asp:Button ID="btnAddAll" runat="server" Text="Add All"
OnClick="btnAddAll_Click"
CssClass="grey_btn_75" />
<div class="spacer"></div>
<asp:Button ID="btnAdd" runat="server" Text="Add"
OnClick="btnAdd_Click"
CssClass="grey_btn_75" />
<div class="spacer"></div>
<asp:Button ID="btnRemove" runat="server" Text="Remove"
OnClick="btnRemove_Click"
CssClass="grey_btn_75" />
<div class="spacer"></div>
<asp:Button ID="btnRemoveAll" runat="server" Text="Remove All"
CssClass="grey_btn_75"
OnClick="btnRemoveAll_Click" /><br />
</div>
CSS:
.grey_btn_75
{
background: url(../images/grey-75px.png);
background-repeat: no-repeat;
border-style: none;
font-family: Arial,Helvetica,Sans-Serif;
font-size: 12px;
font-weight: bold;
width: 75px;
height: 23px;
color: #000000;
cursor: pointer;
}
Things I have tried so far:
I removed the CssClass and the buttons still did not show up.
I modifed the CssClass and the buttons still did not show up.
I put other controls such as an asp:Label and and asp:ImageButton and they showed up fine.
I tried putting a new button and it did not show up.
Your div width is 70px, your button is 75px. You need to clean that up.
The problem is with the styles. Try commenting them out to see which one (or the combination) is responsible for the buttons to disappear.
Don't forget about the inline style of the top DIV as well.
This is a nice guide for button styles:
http://particletree.com/features/rediscovering-the-button-element/
People recommend
width:auto;
overflow:visible;
specifically for IE
I think it is the color value you have set in your CSS. I got the same problem previously and what I did was change the color value to something else.

Resources