修改< HEAD>从ASP.NET AJAX [英] Modify <head> from ASP.NET AJAX

查看:126
本文介绍了修改< HEAD>从ASP.NET AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到ASP.NET AJAX应用程序。我有一个ASP.NET主题两个CSS文件。我用每个回发的CSS中的任何一个依赖于一个条件。

I have recently upgraded to ASP.NET AJAX application. I have two css files in an ASP.NET theme. I use any one of the css per postback depends upon a condition.

previously与我的非Ajax的ASP.NET应用程序,我用做的是

Previously with my non-AJAX ASP.NET application, what I used to do is

protected void Page_PreRender(object sender,
                                  EventArgs eventArgs)
    {
        ControlCollection headCollection = Header.Controls;

        for (int i = 0; i < headCollection.Count; i++)
        {
            Control temp = headCollection[i];
            if (temp is HtmlLink)
            {
                if (/* condition to loads a.css */)
                {
                    if (((HtmlLink) temp).Href.EndsWith("a.css", true, null))
                    {
                        headCollection.RemoveAt(i);
                        break;
                    }
                }
                else
                {
                    if (((HtmlLink) temp).Href.EndsWith("b.css", true, null))
                    {
                        headCollection.RemoveAt(i);
                        break;
                    }
                }
            }
        }
    }

但这块code,当我迁移到ASP.NET AJAX不起作用。我已经检查并发现只有第一次请求加载CSS仍然存在。即,如果a.css装载在第一请求,然后需要b.css上的特定回发要加载不起作用。

But this piece of code does not work when I migrated to ASP.NET AJAX. I have inspected and found that only the loaded css from the first request persists. i.e., if a.css is loaded on the first request, and then b.css is required to be loaded on a specific postback does not work.

请评论,如果你感到困惑的问题。

Please comment if you are confused about the problem.

推荐答案

由于邪恶,解决了使用jQuery和选择。问题

Thanks Unholy, solved the problem using jQuery and selector.

就用这个:

$("head > link[href$='a.css']").remove();

这篇关于修改&LT; HEAD&GT;从ASP.NET AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆