?
Solved

How to use external Style sheet in ASP.net Mobile

Posted on 2009-02-11
8
Medium Priority
?
1,600 Views
Last Modified: 2013-12-27
Hi Experts,
Any one know how to use external Style sheet in ASP.net 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" />
   </mobile:StyleSheet>



Thanks in advance.
0
Comment
Question by:mkdev2009
  • 6
  • 2
8 Comments
 
LVL 13

Expert Comment

by:myderrick
ID: 23620298
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:
http://forums.asp.net/t/1088153.aspx

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

Additional:
http://www.developershome.com/wap/wcss/wcss_tutorial.asp?page=howToApplyStyles

MD
0
 

Author Comment

by:mkdev2009
ID: 23620698
Appreciate if some one can give me some sample.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:myderrick
ID: 23620829
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"
            Page.Header.Controls.Add(objLink)

Good luck.


0
 
LVL 13

Expert Comment

by:myderrick
ID: 23620928
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
Page.Header.Controls.Add(link);

I also fond these:

http://forums.asp.net/p/892044/950821.aspx
http://blogs.msdn.com/csimpkins/archive/2008/02/28/using-css-within-ascx-files.aspx

MD
0
 
LVL 13

Accepted Solution

by:
myderrick earned 1000 total points
ID: 23620969
This is very very similar to your issue:
http://forums.asp.net/t/1357842.aspx

Try it while we wait for other experts to comment.

MD
0
 

Author Comment

by:mkdev2009
ID: 23628869
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
</mobile:StyleSheet>

 

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

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

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"/>
0
 
LVL 13

Expert Comment

by:myderrick
ID: 23631577
Glad we solved it....

MD
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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