开发者

Calling method from class to set css file of page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 7 years ago.

Improve this question

the class_stylesheet.cs

usin开发者_运维技巧g System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


/// <summary>
/// Summary description for class_stylesheet
/// </summary>
public class class_stylesheet
{
    public class_stylesheet()
    {
        //
        // TODO: Add constructor logic here
        //

        private void set_style_sheet(object sender, EventArgs e)
        {
             //<link href="dark.css" rel="stylesheet" type="text/css" id="stylesheet" />

        HtmlLink styleLink = new HtmlLink();
        styleLink.Attributes.Add("rel", "stylesheet");
        styleLink.Attributes.Add("type", "text/css");
        //styleLink.Href = "http://example.com/css/mystylesheet.css";
        styleLink.Href = "LAYOUT1.css";
        //Page+=(Page)sender;
        this.Page.Header.Controls.Add(styleLink);
        }//set style sheet




    }
}


a question asked in haste

well the answer, to help others like me :) is

class_stylesheet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


/// <summary>
/// Summary description for class_stylesheet
/// </summary>
public class class_stylesheet
{
    public class_stylesheet()
    {
        //
        // TODO: Add constructor logic here
        //
    }



    public static void set_style_sheet_layout1(object sender, EventArgs e)
    {
        //<link href="dark.css" rel="stylesheet" type="text/css" id="stylesheet" />

        HtmlLink styleLink = new HtmlLink();
        styleLink.Attributes.Add("rel", "stylesheet");
        styleLink.Attributes.Add("type", "text/css");
        //styleLink.Href = "http://mydomain.com/css/mystylesheet.css";
        styleLink.Href = "LAYOUT1.css";
        Page the_page = new Page();
        //this.Page.Header.Controls.Add(styleLink);
        the_page = (Page)sender;
        the_page.Header.Controls.Add(styleLink);
    }//set style sheet







}

layout.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Layout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

            //linking the page to the style sheet
        class_stylesheet.set_style_sheet_layout1(sender, e);






    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜