【发布时间】:2014-11-13 04:41:50
【问题描述】:
我有一个用 html 编写的前端,我正在将其转换为 asp,并且许多控件的名称中都带有“-”。这引起了疯狂的头痛,因为没有时间重命名所有内容,并且 ctrl-f 和 replace 以某种方式破坏了我的 css。当它们有破折号时,有什么方法可以在后面的代码中访问这些控件?下面的代码我试过了。
//Can find when there is no dash in it, but that breaks the css after find/replace of full solution
HtmlGenericControl body = (HtmlGenericControl)this.Page.FindControl("page-list");
body.Attributes.Add("class", GlobalVariables.webAppSkin);
//I have also tried this, but logout stays null
WebControl logout = (WebControl)Page.FindControl("logout-link");
这是 html 控件:
<body id="page-list">
【问题讨论】:
-
你试过
this.Page.FindControl(@"page-list");我不确定这是否有效,但我稍后会尝试。 -
是的,还是抓不到那个讨厌的控件。
-
@Greg "page-list" 没有任何需要转义的字符,因此使用字符串文字不会有任何区别。
-
我相信这是不可能的。此外,您无法在后面的代码中找到未标记 runat="server" 的控件。您需要在 HTML 标记和 CSS 中重命名并添加上述属性。查找和替换。
-
@TylerH JQuery UI?这是我很久没有听到的名字了。我感觉到你的痛苦。祝你好运。