Solved

asp.net button styles

Posted on 2004-03-25
7
1,417 Views
Last Modified: 2010-08-05
I am doing a project in asp.net.  The site has a dozen asp web control buttons on it.  The client wants a certain style applied to all buttons.  What do I put in the style sheet?
0
Comment
Question by:dbyrne03
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10676923
the style sheet.

.buttclss {color:blue; other properties etc}

The in you code where you generate the buttons add a class attribute:

class="buttclss"

Cd&
0
 

Author Comment

by:dbyrne03
ID: 10679367
I was hoping to avoid this because although it allows me to centrally manage the behavior and appearance of buttons from one file, the style sheet, I still have to go around to every button in the site and type " class='buttclss'" .  For example, if you want to apply a style to all <td> elements, you don't need to put class='tdclss' in every <td> element in your site, you just put
td { color:blue }
in the style sheet.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10682028
Not necessarily.  you could do it dynamically with script:

<script type="text/javascript">
<!--
function setstyle()
{
   for (i=0;i<document.forms.length;i++)
   {
      frm=document.forms[i]
      for (j=0;j<frm.elements.length;j++)
       {
           target=frm.elements[j];
           if (target.type=="BUTTON" || target.type=="SUBMIT" || target.type=="RESET")
target.className="buttclss";
        }
     }
 }
onload.=setstyle;
//-->
</script>

Just put that in a .js file and source it in in the head of the pages.

Cd&
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:dbyrne03
ID: 10682463
couple of quick things.  first, thanks for the script.  there was an error for
onload.=setstyle;
so I changed it to
onload=setstyle;

But it still didn't work.  So I put
alert(target.type);
right before
target.className="buttclss";

the weird thing is, the alert box does not pop up, but the style does take effect.  what is even more weird, the style is applied to textboxes as well.  check out http://137.229.174.53:8080/search.aspx
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 100 total points
ID: 10683034
My bad.  I didn't deal with the case.  The if needs to look like this.

if (target.type.toLowerCase()=="button" || target.type.toLowerCase()=="submit" || target.type.toLowerCase()=="reset")
{
target.className="buttclss";
}

What happened when you put the alert in is it change the scope of the if.  An if without {} has a scope of just the next command.  So setting the class became unconditional.

Cd&
0
 

Author Comment

by:dbyrne03
ID: 10683503
that was it.  thanks buddy.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10695029
Glad I could help.  Thanks for the A/ :^)

Cd&
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now