Dynamically register a script file with the client

Source: Internet
Author: User

// Register the script file with the client

Public static bool registscript (page, string path)
{
Bool isregisted = false;
If (! String. isnullorempty (PATH ))
{
Path = page. resolveurl (PATH );
If (! Page. clientscript. isclientscriptincluderegistered (page. GetType (), PATH) // you can check whether the client has registered the script file.
{
Page. clientscript. registerclientscriptinclude (page. GetType (), path, PATH); // register the specified script file with the client
Isregisted = true;
}
}
Return isregisted;
}

// Dynamically register CSS files with the client to avoid CSS conflicts on the IE registration page due to repeated CSS file registration

Public   Static Bool Registcss (Page, string pathcss) {bool Addcss = True ; If (Page. header! = Null ) {Controlcollection Cccollection = Page. header. controls; If (Cccollection. Count> 0 ){ Foreach (Control Citem   In Cccollection ){ If (Citem. GetType () = Typeof (Htmllink) {htmllink Hllink = Citem As Htmllink; If (Hllink. attributes [ "Href" ]. Tostring () = page. resolveurl (pathcss) {addcss = False ;}}}} If (Addcss) {htmllink Csslink =New Htmllink {href = page. resolveurl (pathcss)}; csslink. Attributes. Add ( "Rel" , "Stylesheet" ); Csslink. Attributes. Add ( "Type" , "Text/CSS" ); Page. Page. header. Controls. Add (csslink );}} Return Addcss ;}

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.