Asp.net custom control development for Alibaba Cloud (5)-embedded Resources

Source: Internet
Author: User

  • Summary

In the previous article, we talked about how to save the control state of VitwState. This chapter describes how to embed css files, js files, and Image files.

  • Content

With the improvement of my controls, our target control DropDwonCheckList will eventually display a lot of Html code. Although we can use C # To control the style, it is too costly and difficult to maintain, the reusability is low, and the style will also be presented with the display of the control, without achieving real encapsulation. By studying the content of this chapter, you can do an experiment to see the HTML code that is presented without using the embedded style sheet method.

The embedded resources are divided into three steps:

1. Create a new folder at the xyb.controlslayer, named cssfolder, and then the dropdwon.css sample file to set the dropdwon.css Style File Attribute to an embedded resource.

2. Modify the AssemblyInfo. cs file and add the following line of code in it.

[assembly:System.Web.UI.WebResource(,)]

Xyb.controlsis my name space, css is my folder name, dropdwon.css is the file name, that is, namespace + folder + file name, if there is no folder, you do not need to write the folder name, "text/css", is the MIME type, if you do not know the MIME type, go online to Baidu. This is not in our scope.
3. Load and use the program. We will write some code in the override OnPreRender method (pre-rendering occurs before Render) and load the embedded css file.

                                (.Page.Header.FindControl()==                 cssHref = .Page.ClientScript.GetWebResourceUrl(.GetType(), cssLink = .Format(= = 

Now, the Render method is commented out by pnlDropDown. Style ["border"] = "1px solid # ccc"

          = = ;            pnlDropDown.Height ==            pnlDropDown.RenderControl(writer);        } 

I will paste the code on the dropdwon.css page.

 

I will paste the code of the entire page to make it easy for everyone to be lazy. Just copy it. Later, I may not paste the code of the whole page.

System. ComponentModel; Attributes and fields), Category () {ViewState [] =? : Convert. ToInt32 (ViewState [{ViewState [] = {ViewState [] =? : Convert. toInt32 (ViewState [{ViewState [] = (. page. header. findControl () = cssHref =. page. clientScript. getWebResourceUrl (. getType (), cssLink =. format (===; pnlDropDown. height = pnlDropDown. renderControl (writer );

Finally, we will generate a new one and run it to check the effect. The same is true, as shown below:

The preceding example shows that the. CSS file has been embedded, and the source file presented by. CSS is also pasted.

<Link href = '/WebResource. axd? D = olxWdg1PRQwoM2C5kFryz0r-e5iv0mo6Hhq6QXJVp3rCs-vS9V1D3mWKk95a425mVceqNdG1fXuFTymtP59K-0A6o0FVd_i5wW8rUi6taUIt5QeywuRKjRDmrg7pOdq9Ydt1IMEaOQ5PL2tF9yCGOQ2 & t = 635150192328935925 'rel = 'stylesheet 'type = 'text/css'/>

  • Next episode notice

Embed the. js file. Stay tuned to me. If you have any questions, leave me a message.

 

  

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.