This control should be used instead of standard HTML head tag in order to render dynamicaly registered head scripts and stylesheets.
If you need to use ASP.NETs built-in <head> tag, you should nest Spring's Head within ASP.NET's: <html> <head> <title>Some Title</title> <spring:head> <-- will render styleblocks etc. here --> </spring:head> </head> </html>
Inheritance: System.Web.UI.Control
Ejemplo n.º 1
0
        public void StyleBlockRendersTypeAttribute()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);

            page.Styles.Add("stylename", "stylevalue");

            string result = page.Render(string.Empty);
            string expect = @"<head><style type=""text/css"">stylename { stylevalue }</style></head>";
            Assert.AreEqual(expect, result);
        }
Ejemplo n.º 2
0
        public void StyleFileRendersTypeAttributeAndUsesCssRootPath()
        {
            const string STYLESHEETPATH = "filepath";

            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                Head head = new Head();
                page.Controls.Add(head);

                page.CssRoot = "testcssroot";
                page.StyleFiles.Add("filename", STYLESHEETPATH);

                string result = page.Render(string.Empty);
                string expect = string.Format(@"<head><link rel=""stylesheet"" type=""text/css"" href=""/testcssroot/{0}"" /></head>", STYLESHEETPATH);
                Assert.AreEqual(expect, result);
            }
        }
Ejemplo n.º 3
0
        public void DontRenderHeadTagIfNestedWithinStandardHeadControl()
        {
            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                HtmlHead htmlHead = new HtmlHead();
                Head head = new Head();
                head.Controls.Add(new LiteralControl("literal child"));
                htmlHead.Controls.Add(head);
                page.Controls.Add(htmlHead);

                // initialize page to force head control initialization
                page.InitRecursive(null);
                string result = page.Render(string.Empty);
                string expect = @"<head>literal child<title></title></head>";
                Assert.AreEqual(expect, result);
            }
        }
Ejemplo n.º 4
0
        public void ScriptBlockRendersTypeAttribute()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);

            page.RegisterHeadScriptBlock( "scriptname", "scriptcode" );

            string result = page.Render(string.Empty);
            string expect = @"<head><script type=""text/javascript"">scriptcode</script></head>";
            Assert.AreEqual(expect, result);
        }
Ejemplo n.º 5
0
        public void RenderChildrenFirst()
        {
            TestPage page = new TestPage();
            Head head = new Head();
            page.Controls.Add(head);
            
            head.Controls.Add(new LiteralControl("literal child"));
            page.Styles.Add("stylename", "stylevalue");

            string result = page.Render(string.Empty);
            string expect = @"<head>literal child<style type=""text/css"">stylename { stylevalue }</style></head>";
            Assert.AreEqual( expect, result);
        }
Ejemplo n.º 6
0
        public void ScriptFileRendersTypeAttributeAndUsesScriptsRootPath()
        {
            const string SCRIPTFILEPATH = "filepath";

            using (new TestWebContext("/", "testpage.aspx"))
            {
                TestPage page = new TestPage(HttpContext.Current);
                Head head = new Head();
                page.Controls.Add(head);

                page.ScriptsRoot = "testscriptroot";
                page.RegisterHeadScriptFile("filename", SCRIPTFILEPATH);

                string result = page.Render(string.Empty);
                string expect = string.Format(@"<head><script type=""text/javascript"" src=""/testscriptroot/{0}""></script></head>", SCRIPTFILEPATH);
                Assert.AreEqual(expect, result);
            }
        }