The benefits are there, and the problem goes on. It turns out that there are CSS introductions and some JavaScript functions on channel pages and list pages, and how do you handle these CSS styles and JavaScript functions when you're using a master page in a content page? As you know, content pages that use master pages cannot contain
Copy Code code as follows:
static public class Controlhelper
{
static public void Addstylesheet (Page page, string csspath)
{
Htmllink link = new Htmllink ();
Link. Href = Csspath;
Link. attributes["rel"] = "stylesheet";
Link. attributes["type"] = "text/css";
Page. HEADER.CONTROLS.ADD (link);
}
}
So, on a specific page, we can add a CSS reference to the following code:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
Controlhelper.addstylesheet (this. Page, "Css/projectpage.css");
}
The benefit of this solution is that you can dynamically change the CSS files that you want while the program is running, but what do you do with JavaScript functions? Besides, is it necessary to add CSS and JavaScript that should be added to the HTML code through CS code? Therefore, this kind of solution is also very quickly rejected by me. The third remaining solution is to add a content control to the In the daytime, seeing this I thought that this method did not work, almost gave up. Evening home to find a better solution, but all the articles are basically said the first two, on the third solution someone said that the error, No. It seems that there are a lot of people who give up after this hint. I didn't get this wrong. Go directly to the content page and insert the following code in the content page:
Look, there is no error in the content page, it seems to have a chance. To go to the design view of the content page, the following interface appears:
Heart cool a bit, because I did not see the effect of the CSS style applied above, my CSS file code is as follows:
Copy Code code as follows:
#content
{
Text-align:center;
width:200px;
height:100px;
Background-color: #00FF00;
Color: #FF0000;
font-size:12px;
}
That is to let the ID content div width 200px, height 100px, text center, background color is green, the font is red, 12px. Not reconciled I pressed the F5 debugging keys, a surprising picture appeared:
This shows that the CSS application was successful and also saw the test cute Hello World dialog alert came out. It worked!
To sum up, many people actually start thinking like me, how to use CSS and JavaScript in content pages in the simplest way. Many of them may also have found the article I found, but when I met the error in my master page, I gave up, maybe someone stuck to the second step, but did not see the application of CSS in Design view may also give up. In fact, as long as the persistence of success! Yu Shivi said good "than others think a little more, you can succeed!" "It does make sense," he said.