gpt4 book ai didi

c# - ASP.NET:更改隐藏代码中的 CSS 链接 href?

转载 作者:太空宇宙 更新时间:2023-11-04 15:58:30 25 4
gpt4 key购买 nike

我有一个 .ASPX 页面,我想在其中更改隐藏代码中的 CSS href。我搜索了几种技巧来执行此操作,但找不到任何符合我预期的方法。

HTML 标记:

<link id="linkCSS" runat="server" href='/css/1.css' rel="stylesheet" type="text/css" />

这就是我在代码隐藏中尝试的:

If (mobile)
{
HtmlLink link = (HtmlLink)this.FindControl(linkCSS.UniqueID);
link.Href = "/css/2.css";
}

但是我得到以下异常:

Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.HtmlControls.HtmlLink'.

有什么想法吗?谢谢。

最佳答案

不需要自己找css,改成如下。

If (mobile)
{
linkCSS.Attributes["href"] = "~/css/2.css";
}

我已经提交了 This Link.

关于c# - ASP.NET:更改隐藏代码中的 CSS 链接 href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com