How to set a:visited and a:hover programmatically in ASP.NET - c#

Can someone tell me how to set a:visited and a:hover programmatically? I am dynamically building up some hyperlinks server-side and want to know how to specify unique css behaviour for each link. Otherwise I would set them all in a stylesheet.

If you want to set the style for a single item, you can use the CssClass attribute, then set up the classes in your css.
.linkA:visited {
color: red;
}
.linkB:visited {
color: blue;
}
In your codebehind:
LinkOne.CssClass = "linkA";
LinkTwo.CssClass = "linkB";

not sure I understand - wouldnt this work?
Hyperlink1.CssClass = MyAnchorClass;

Unless things have changed, you can't specify the a:visited and a:hover within an HTML anchor (a) tag, so in the end you will need CSS somewhere (on the page, in a file) and assign the class to each anchor tag, like what willoller said.

Here's how you do it inside code:
imageButton.Attributes.Add("onmouseout",
"this.src='../../../App_Themes/White/Images/default.png';");
imageButton.Attributes.Add("onmouseover",
"this.src='../../../App_Themes/White/Images/default.hover.png';");
imageButton.ImageUrl = "~/App_Themes/White/Images/default.png";

Related

How do you use a css style for Response.Write method?

There are examples in here for applying a .css style for c# controls. But how do you use a .css style for Response.write method?
string style = #"<style> table, td, th { border: 1px solid green; } th { background-color: green; color: white;} </style>"
context.Response.Write(style);
My understanding is that your question is about how to provide CSS classes from css file to Response.Write method. You may have to read the file (you can use System.IO namespace to open and read the file). Since CSS file may have comments as well, you may need to parse it if you want to get rid of it. You can probably explore the CSS parser given here or write your own CSS parser. This answer is based on discussion here

Dynamic JQUERY data table width issue in IE7

We have created a dynamic JQUERY table with dynamic columns (Depending upon count value) and assigned it to DIV tag. However the thead and tbody is going outside DIV tag in IE7.
Looks like the width is automatically set dynamically by CSS, we are not able to override it.
Did anyone faced similar issues. Please help.
use important keyword like this.
width: 100px !important;
Added the following lines in DataTable.css file and it worked perfectly!!
table.display thead th div.DataTables_sort_wrapper
{
/*Fix for width issue*/
position: relative;
clear: both;
width:50px;
overflow:hidden;
word-wrap:break-word;
}

Problems changing css properties of hyperlink in gridview

I have an asp.net gridview and have just added sorting to the columns. This has now obviously changed the column headers to links and they have changed to a blue colour but for some reason my modifications to change the colour of the links isn't working and they just wont pick-up the correct style.
Here is some CSS that I tried, I have tried it a few other ways too but wanted to test it using the most basic setup:
a:link {
color:white;
}
a:visited {
color:white;
}
use !important with Sachin's answer
a{
color:white !important;
}
Try this
div #something .gridview td a{
Color: red! important;
}
Try to set style more specific to your anchor tag.

Creating a CSS class programmatically ASP.Net

I have a DIV that I would like to modify the CSS for programmatically in VB.Net/C#.
I know that, for example, I could add style attributes simply by
divMyDiv.Style.add("color","#ff0000")
but I want to add a new CSS class, together with its attributes to the DIV. So in an ideal world I would like to write something like
divMyDiv.Style.add(".smallRedText", "{font-size:10px; color:#ff0000}")
Is this even possible ? Am I missing the bigger picture ?
All help gratefully received :-)
What about:
divMyDiv.Attributes.Add("class", "new-class")
I suggest that you define the variations in css ahead of time that you know you'll need. Then, you can manipulate the class attribute of whatever control you need to change on the fly.
For example, you could define:
.smallRedText { font-size: 10px; color: #ff0000 }
.smallBlueText { font-size: 10px; color: #0000ff }
Then when comes time to select dynamically:
divMyDiv.Attributes.Add("class", whateverClassWeNeed);

Hiding a control in Asp.net using css

i am trying to make the control not visable through the css but still the control is been shown.
i tried doing like this
html1.Visible = false;
but this creates an gap in the menu where is been used
HtmlAnchor html1 = (HtmlAnchor)holder.FindControl("lblA1");
html1.Attributes.Add("class", "display:none");
i want to hide the control and do not want to display the gap there
how can we achive this.
any help on this would be great
You just need to use style instead of class:
html1.Attributes.Add("style", "display:none");
You may also consider the option of making a CSS style like:
.hidden
{
display:none;
}
And then apply it via 'class':
html1.Attributes.Add("class", "hidden");
If you want to add more than one property in style element in that case use Style property instead of Attributes property like this example....
HtmlAnchor html1 = (HtmlAnchor)Page.FindControl("lblA1");
html1.Style.Add("display", "none");
You can attach this class to button using above methods
Very helpful when the button is taking the space , which it shouldn't be
<style>
.hideAspButton
{
position: absolute;
visibility: hidden;
}
</style>

Categories

Resources