Search code examples
asp.netskin

Applying skin file for button in ASP.net


I am very new to ASP.net and trying to apply styles to button in my webform I have done the following

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="TestingStyles.Index" Theme="button" %>
<asp:Button  runat="server" Text="Button" Width="221px" SkinID="btnskin" />

above is my index.aspx and below is my button.skin

 <asp:Button runat="server" 
  BackColor="Red" 
  ForeColor="White" 
  Font-Name="Arial" 
  Font-Size="9px"
  SkinID="btnskin"
/>

above is my test.skin file I have added it's reference in the webform page theme directive. I am having two problems

1) Buttins in my webforms are not getting styled according to skin file? 2)Intellisense is not working in skin file?


Solution

  • Here you forgot to give skinid to your button. It should be like this -

    <asp:Button runat="server" 
      BackColor="Red" 
      ForeColor="White" 
      Font-Name="Arial" 
      Font-Size="9px"
      skinid="btnSkin"
    />
    

    and then set your theme folder which is in App_Themes to your page directive like this -

    <%@ Page Language="C#" Theme="ThemeFolderName" AutoEventWireup="true" .. %>
    

    Or if you don't want to repeat this code in every page then set it into web.config like this -

    <system.web>
        <pages styleSheetTheme="ThemeFolderName"></pages>
    </system.web>
    

    and apply it to button like this -

    <asp:Button ID="btnUsers" runat="server" SkinID="btnSkin">