How to use external Style sheet in Mobile

Hi Experts,
Any one know how to use external Style sheet in Mobile?

below are the style sheet that i have created in a ascx page.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="mStyle.ascx.cs" Inherits="mStyle" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
  <mobile:StyleSheet Runat="server" ID = "CSS">
       <mobile:Style name ="style1" Font-Name ="Arial" BackColor= "#3399ff"  Font-Size="Large" />

Thanks in advance.
Who is Participating?
This is very very similar to your issue:

Try it while we wait for other experts to comment.

This time we would find a solution:

First use mobile:Style Name (watch the capitals)

Someone has a similar problem and the discussion in  here:

I think it is to do with the Doctype or codes....


Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

mkdev2009Author Commented:
Appreciate if some one can give me some sample.
You may want to try this. Care must be taken. Keep a backup of your initial code - Just in case
To Attach css file, used code:

            Dim objLink As New HtmlLink()
            objLink.ID = ID
            objLink.Attributes("rel") = "stylesheet"
            objLink.Attributes("type") = "text/css"
            objLink.Href ="filname.css"

Good luck.

Another method would be to put this code in the Page_Load event handler:

HtmlLink link = new HtmlLink();
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("type", "text/css");
link.Href = "~/StyleSheetPath"; // Replace with actual path of the style sheet

I also fond these:

mkdev2009Author Commented:
myderrick, thanks for the links that you provided. I finally found a solution.

This is the solution :

create a user control... You can select a mobile user control template... I had named that as stylesheet.ascx...

<%@ Control Language="C#" AutoEventWireup="true" Inherits="TestApp.stylesheet" Codebehind="stylesheet.ascx.cs" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

The page by default contains the above two lines of code...

Then type...

<mobile:StyleSheet ID="StyleSheet1" Runat="server">

//You can use various styles here
<mobile:Style Name="exstyle1" Alignment="NotSet" BackColor="#fdfeba" Font-Size="Large" Font-Name="Arial" ForeColor="Red" Font-Italic="True"></mobile:Style>

<mobile:Style Name="exstyle2" Font-Name="Times New Roman"

//End of style defentions


Then in your aspx page, include this tag inside <body> before the <mobile:form> tag,

<mobile:StyleSheet ID="StyleSheet1" ReferencePath="stylesheet.ascx" Runat="server">

then you can use the syles to your controls like

<mobile:Form id="Signup_Form" StyleReference="exstyle1"  runat="server">

 <mobile:TextBox id="txt1" StyleReference="exstyle2" runat="server"/>
Glad we solved it....

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.