1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add Scripts and css embeded files from SimpleControl

Add Scripts and css embeded files from SimpleControl

2 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    28 Oct 2009
    Link to this post
    Hi,

    What is the best way to add to head of pages the internal resources using one dll SimpleControl. Could you suggest some easier way and the best event to use for compiled resources.
    Thanks.
  2. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    28 Oct 2009
    Link to this post
    Ok, Sorry. Override OnPreRender of SimpleControl class

     protected override void OnPreRender(EventArgs e)  
            {  
                base.OnPreRender(e);  
                //registering one script from resources  
                this.Page.ClientScript.RegisterClientScriptResource(typeof(Web.UI.Public.MyClass), "Web.UI.Resources.Frontend.resource.js");  
                HtmlHead head = (HtmlHead)Page.Header;  
                HtmlLink css = new HtmlLink();  
                css.Attributes.Add("href", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "Web.UI.Resources.Frontend.css.MyStyle.css"));  
                css.Attributes.Add("type", "text/css");  
                css.Attributes.Add("rel", "stylesheet");  
                head.Controls.Add(css);  
     
                //string includeTemplate ="<link rel='stylesheet' text='text/css' href='{0}' />";  
                //string includeLocation = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Web.UI.Resources.Frontend.css.MyStyle.css");  
                //LiteralControl include = new LiteralControl(String.Format(includeTemplate, includeLocation));  
                //((HtmlControls.HtmlHead)Page.Header).Controls.Add(include);  
     
                ////registering script block  
                //Guid guid = new Guid();  
                //this.Page.ClientScript.RegisterClientScriptBlock(typeof(Web.UI.MyClass), guid.ToString(), "accion('" + this.YourDiv.ClientID + "', '" + str + "');", true);  
                ////add one script attribute  
                //this.YourControl.Attributes["onclick"] = "action('" + this.yourDiv.ClientID + "', this.value);";  
            } 

    What about cache for these internal resouces?

    Regards
2 posts, 0 answered