<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET AJAX Discussion and Suggestions</title><link>http://forums.asp.net/1007.aspx</link><description>This forum is the place for ASP.NET AJAX 'getting started' questions, general questions that don't fit in one of the other forums about AJAX </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1537104.aspx</link><pubDate>Wed, 17 Jan 2007 23:35:33 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1537104</guid><dc:creator>Rama Krishna</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1537104.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1537104</wfw:commentRss><description>&lt;p&gt;The easiest way to do this is to use ScriptManager.RegisterClientScriptBlock. &lt;/p&gt;
&lt;p&gt;In your control add the following function:&lt;/p&gt;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;void&lt;/span&gt; AddHtmlLink(&lt;span class=kwd&gt;string&lt;/span&gt; rel, &lt;span class=kwd&gt;string&lt;/span&gt; href, &lt;span class=kwd&gt;string&lt;/span&gt; type)
{
    ScriptManager manager = ScriptManager.GetCurrent(Page);
    &lt;span class=kwd&gt;if&lt;/span&gt; (manager.IsInAsyncPostBack)
    {
        Dictionary&amp;lt;&lt;span class=kwd&gt;string&lt;/span&gt;, &lt;span class=kwd&gt;object&lt;/span&gt;&amp;gt; values = &lt;span class=kwd&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class=kwd&gt;string&lt;/span&gt;,&lt;span class=kwd&gt;object&lt;/span&gt;&amp;gt;();
        values.Add(&lt;span class=st&gt;"rel"&lt;/span&gt;, rel);
        values.Add(&lt;span class=st&gt;"href"&lt;/span&gt;, href);
        values.Add(&lt;span class=st&gt;"type"&lt;/span&gt;, type);

        JavaScriptSerializer serializer = &lt;span class=kwd&gt;new&lt;/span&gt; JavaScriptSerializer();

        StringBuilder scriptBuilder = &lt;span class=kwd&gt;new&lt;/span&gt; StringBuilder();

        scriptBuilder.Append(&lt;span class=st&gt;"registerLink("&lt;/span&gt;);
        serializer.Serialize(values, scriptBuilder);
        scriptBuilder.AppendLine(&lt;span class=st&gt;");"&lt;/span&gt;);
        ScriptManager.RegisterClientScriptInclude(&lt;span class=kwd&gt;this&lt;/span&gt;, &lt;span class=kwd&gt;this&lt;/span&gt;.GetType(), &lt;span class=st&gt;"LinkRegister"&lt;/span&gt;, &lt;span class=st&gt;"linkRegister.js"&lt;/span&gt;);

        ScriptManager.RegisterClientScriptBlock(&lt;span class=kwd&gt;this&lt;/span&gt;, GetType(), &lt;span class=st&gt;"dynLink"&lt;/span&gt;, scriptBuilder.ToString(), &lt;span class=kwd&gt;true&lt;/span&gt;);
    }
    &lt;span class=kwd&gt;else&lt;/span&gt;
    {
        HtmlLink link = &lt;span class=kwd&gt;new&lt;/span&gt; HtmlLink();
        link.Href = href;
        link.Attributes[&lt;span class=st&gt;"rel"&lt;/span&gt;] = rel;
        link.Attributes[&lt;span class=st&gt;"type"&lt;/span&gt;] = type;
        Page.Header.Controls.Add(link);
    }
}
&lt;/pre&gt;
&lt;p&gt;Here is a sample usage:&lt;/p&gt;&lt;pre class=coloredcode&gt;&lt;span class=kwd&gt;static int&lt;/span&gt; i = 0;

&lt;span class=kwd&gt;protected override void&lt;/span&gt; OnPreRender(EventArgs e)
{
    &lt;span class=kwd&gt;base&lt;/span&gt;.OnPreRender(e);
    
&lt;span class=cmt&gt;//Just some dummy test&lt;/span&gt;
    i = 1 - i;
    AddHtmlLink(&lt;span class=st&gt;"Stylesheet"&lt;/span&gt;, &lt;span class=st&gt;"Test"&lt;/span&gt; + (1-i).ToString() + &lt;span class=st&gt;".css"&lt;/span&gt;, &lt;span class=st&gt;"text/css"&lt;/span&gt;);
}

    &lt;/pre&gt;&amp;nbsp;&amp;nbsp; On other thing you will need is the linkRegister.js file. Which will look like this: 
&lt;p&gt;&amp;nbsp;&lt;pre class=coloredcode&gt;function registerLink(obj) {
 var link = document.createElement('link');
 link.href = obj.href;
 link.rel = obj.rel;
 link.type = obj.type;
 document.getElementsByTagName('head')[0].appendChild(link);
}

Sys.Application.notifyScriptLoaded();&lt;/pre&gt;&amp;nbsp;There is one flaw in this solution: which is that it does not delete the existing link nodes from DOM. This can be easily solved by adding an Id to the link element and removing it before adding a new link. I leave it to you to implement it according to your needs.&lt;/p&gt;</description></item><item><title>Re: register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1537040.aspx</link><pubDate>Wed, 17 Jan 2007 22:44:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1537040</guid><dc:creator>Bort</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1537040.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1537040</wfw:commentRss><description>I don't quite understand what the Page.Theme has to do with my custom control. I don't want to change the Page.Theme because the comsumer of my custom control will want control over his own&amp;nbsp;Page.Theme. I want my custom control, when it is loaded dynamicaly into the consumer's&amp;nbsp;page, on partial postback, to add its own&amp;nbsp;css&amp;nbsp;reference. The custom control should be independent of the page and the consumer should not have to be concerned with adding this reference.</description></item><item><title>Re: register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1534410.aspx</link><pubDate>Tue, 16 Jan 2007 14:14:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1534410</guid><dc:creator>stmarti</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1534410.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1534410</wfw:commentRss><description>&lt;p&gt;From an updatepanel trigger setting the Page.Theme or Page.Title seems to works, but the following not works (would be nice)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HtmlLink link = new HtmlLink( );&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; link.Attributes.Add( "href", "/css/some.css" );&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; link.Attributes.Add( "type", "text/css" );&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; link.Attributes.Add( "rel", "stylesheet" );&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.Header.Controls.AddAt( 0, link ); &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;And because we cannot put an updatepanel inside the head, we are limited to manipulate the content of the head from the server side.&lt;/p&gt;&lt;p&gt;The only way to register a script in the updatepanel trigger (when dynamically adding your custom control), and that javascript (google for examples) could change/add link elements in the head. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;But maybe someone has a better solution for you...&lt;/p&gt;</description></item><item><title>Re: register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1534154.aspx</link><pubDate>Tue, 16 Jan 2007 09:41:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1534154</guid><dc:creator>Bort</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1534154.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1534154</wfw:commentRss><description>&lt;p&gt;Yes, but the styles I am trying to reference have nothing to do with themes. I am building a custom control which must reference a css file if it is to work properly. I am not doing themes for my custom control.&lt;/p&gt;</description></item><item><title>Re: register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1531591.aspx</link><pubDate>Sun, 14 Jan 2007 10:05:25 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1531591</guid><dc:creator>MIB426</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1531591.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1531591</wfw:commentRss><description>&lt;p&gt;you can set different skin in the App_Themes folder&lt;/p&gt;
&lt;p&gt;You can set different theme by using&amp;nbsp;Page.Theme = Mytheme&lt;/p&gt;
&lt;p&gt;You can trigger UpdatePanel event to set Page.Theme&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>register a &lt;link&gt; CSS reference on partial postback</title><link>http://forums.asp.net/thread/1531554.aspx</link><pubDate>Sun, 14 Jan 2007 08:48:52 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1531554</guid><dc:creator>Bort</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1531554.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1007&amp;PostID=1531554</wfw:commentRss><description>How does one go about registering a &amp;lt;link&amp;gt; css reference with the page but only&amp;nbsp;on partial post back. Each partial postback could return a different &amp;lt;link&amp;gt; reference. I have examined all the register methods of the ScriptManager and there isn't any way to do this from what I see.</description></item></channel></rss>