0

How do I customize an asp:Button class?

This is like this proble: How to set css style to asp.net button? but not really since the button is inherited from a cs class.

I have this bit of code in an ASPX file:

<div class="buttonContainer" style="clear:both;width:100%;text-align:left">
   <asp:Button ID="btnProceed" runat="server"  Text="Next" OnClick="ProceedButton_Clicked" Enabled="true" />
</div>

So, if I want to make the button bigger or bolder text, how would I do it?

btnProceed is defined in a .cs file like this:

 protected global::System.Web.UI.WebControls.Button btnProceed;

So, is there some way I can inherit a System.Web.UI.WebControls.Button class and change the font size?

Community
  • 1
  • 1
xarzu
  • 8,657
  • 40
  • 108
  • 160

3 Answers3

4

All your server controls are ultimately going to render some HTML markup to the browser. So Apply a CSS class to your button and style it the way you want. You can use the CssClass property to set it.

<asp:Button ID="btnProceed" runat="server" Text="Hi" CssClass="yourClass" />

And put this style in your css file which is being included in your aspx page.

.yourClass
{
  font-size:72px;
  font-weight:bold;
}
Shyju
  • 214,206
  • 104
  • 411
  • 497
1

You could be able to customize any style for your button with this

.buttonContainer input
{
   font-size: 14px;
   font-weight: bold;
   /**** ETC ***** /
}
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
0

you can set Font Size at server-side by using btnProceed.Font.Size = FontUnit.Point(50);

Phong Vo
  • 1,078
  • 7
  • 16