views:

738

answers:

4

I am developing a C# ASP.Net project. And I would like to do something very similar to what is shown in the following website.

However, that is a solution for the HTML <a> tag, and I am looking for a solution for ASP.NET buttons.

What are my options?

+2  A: 

They are the same, you can do something like this:

<asp:Button ID="SearchButton" runat="server" CssClass="addButtonStyle" OnClick="SearchButton_Click"
            Text="Go&nbsp;" Width="60px" />

some style:
.addButtonStyle {
    border: 1px solid #e1ecfc;
    background-color: #B9D1F4;
    color: #003399;
    background-image: url(partgrad.gif);
    background-repeat: repeat-x;
}
Henry Gao
I'm sorry, but that doesn't seem to solve my problem.The solution you posted doesn't consider MouseOver animation, and it would require doing a "partgrad.gif" image that would fit the exactly size of the button... however, i don't know how many letters will be written in the buton Text property, since it's controled by the client.
Marco
You can specify the width of the button rather than letting it scale with text.
Wyatt Barnett
It's not the same Wyatt, the technique he's referring to requires some extra markup and get multiple background images associated with a single button. If we're splitting hairs, a Button simply cannot do the trick. You can get in the ballpark, visually, but if the goal is pure visual presentation, ASP:Button will fall short.
Jasconius
A: 

If you're looking for an entire library, I can suggest Telerik ASP.NET FormDecorator

Rubens Farias
Thanks, for the suggestion. :)But the plan is not an entire libary... I just want to be able to change one control.
Marco
Plus who want to buy more software.
Adam Smith
+6  A: 

<asp:LinkButton /> is a good choice. It is virtually identical to <asp:Button />, except it creates a form enacting hyperlink that you can put any image in it that you want to.

I stress using LinkButton instead of ImageButton because ImageButton uses different event handlers, which makes it difficult to switch back and forth between them. With Linkbuttons and Buttons, they use the same event handlers, so it's rather easy to switch between them.

Jasconius
How well do your link buttons degrade? Do they work without javascript enabled?
Wyatt Barnett
An excellent question. It's been a while since I've used them, but the reality is that most people, and even many corporations, are not even bothering with javascript-disabled users. Can we name a platform that has no javascript capability more recent than Windows Mobile 5.5?
Jasconius
@Wyatt, anyone surfing the net without javascript enabled, can't really do anything anymore. I think it's about time we just assume javascript is enabled.
Jack Marchetti
Also to the question asker, I forgot to mention, the link you provided shows a technique called sliding glass doors, for scaling buttons. LinkButton won't do this automatically for you, but you can easily extend LinkButton to generate the markup appropriate for supporting width scaling background images. I did that for a site once, it worked nicely.
Jasconius
@JackM, u'r absolutely right about the Js thing.@Jasconius, I just made it work without extending the LinkButton. And it seems to be working fine. I just runned a couple of tests (including IE6) and everything seems to be ok.
Marco
Assuming Javascript for everything is just WRONG WRONG WRONG!! It completely depends on what you're doing, a public website with it's navigation requiring Javascript is next to useless.
roryf
That's a completely idyllic view on web technology and is the manifestation of an opinion, not a fact. ALL major non-mobile browsers, aka over 99% of the market, support javascript, and users have to specifically disable javascript, and those who are savvy enough to do so should be congnisant of the risk they are taking.It's fine if you want to have an opinion, but downranking people because of your opinion is essentially sleezy. The OP wanted to know how to do what was in that tutorial using .NET controls and I told him the easiest way to do it.
Jasconius
Assuming JS might be wrong in some contexts, but for ASP.Net WebForms it's a hard requirement - why fight it?
DDaviesBrackett
A: 

Hey,

Try this example

or view it here My Example Link

<!DOCTYPE html>
<html>
<head>
 <title>Hello World | Button Config</title>
</head>
<body>
<div>




 <h1>Working with Buttons</h1>
 <p>Small, large, or medium size buttons can have css properties that you can benefit from rather that using images. Please look at the examples below</p>

<textarea>
<asp:button runat="server" id="helloWorld" CssClass="button" text=" --- See examples --- " />
</textarea>


 <ol>
  <li>
   <input type="submit" class="button" value="This is a Long Button"/>
  </li>
  <li>
   <input type="submit" class="button" value="Search Now!"/>
  </li>
  <li>
   <input type="submit" class="button" value="Short"/>
  </li>
 </ol>

 <ol>
  <li>
   <input type="submit" class="button round" value="This is a Long Button"/>
  </li>
  <li>
   <input type="submit" class="button round" value="Search Now!"/>
  </li>
  <li>
   <input type="submit" class="button round" value="Short"/>
  </li>
 </ol>

 <p>
  In theory you always want the cleanest markup. So linkButtons on are NO GO! LinkButtons are Javascript based and can cause accessibility issues.
 </p>

 <h3>IE doesn't have my rounded corners?</h3>
 <p>
  Gotcha, lets do it without JS and lets use the images found from the link below. IE doesnt take advantage of some of the cooler CSS tricks we find in other browsers. - Shame on them! In the next example we simply wrap the asp:button with a span and then a b element.
 </p>

 <ol>
  <li>
  <span id="btn-wrap">
   <b>
    <input type="submit" class="rounded" value="This is a Long Button"/>
    </b>
   </span>  
  </li>
  <li>
  <span id="btn-wrap">
   <b>
    <input type="submit" class="rounded" value="Search Now!"/>
    </b>
   </span>
  </li>
  <li>
  <span id="btn-wrap">
   <b>
    <input type="submit" class="rounded" value="Short"/>
    </b>
   </span>
  </li>
 </ol>


<textarea>
<span id="btn-wrap">
<b>
 <asp:button runat="server" id="helloWorld" text=" --- See examples --- " />
</b>
</span>
</textarea>


 <h3>Wrapping it up</h3>

 <p>
  In this demo, you've seen a single background image used as a repeating object to give us a gradient effect similar to the one found here <a href="http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html"&gt;http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html&lt;/a&gt;
 </p>


 <style>
  input[type="submit"], span, b {background:transparent none repeat scroll 0 0;border:0 none;display:inline-block;margin:0;padding:0;cursor:pointer;outline:none;} /* reset the button */
  input.button {background:url(http://gfx2.hotmail.com/cal/11.00/updatebeta/ltr/grid_navigator_bg.png) repeat-x; text-shadow:0 1px 1px #FFFFFF /* Just for looks */; padding:4px 5px;}
  input.button:active {background:#FED58F;}

  .round {-moz-border-radius:8px; -webkit-border-radius:8px; border-radius:8px;}

  /* http://gfx2.hotmail.com/cal/11.00/updatebeta/ltr/grid_navigator_bg.png thank you hotmail for the image */
  span#btn-wrap {background:transparent url(http://www.oscaralexander.com/tutorials/img/bg_button_span.gif) repeat-x scroll 0 0;}
  span#btn-wrap b {background:transparent url(http://www.oscaralexander.com/tutorials/img/bg_button_a.gif) no-repeat scroll right 0;height:18px;padding:3px 10px;}
  span#btn-wrap:active {background-position: 0 -24px;}
  span#btn-wrap:active b {background-position: right -24px;}

  li {margin:5px 0;}

  textarea {background:#323232; color:white; padding:10px; width:900px; height:80px; overflow:hidden;}
 </style>
</div>
</body>
</html>

Like the page says, this is the cleanest java Script less way to do it. This is accessible and browser friendly.

Erik5388