【发布时间】:2011-02-15 11:40:29
【问题描述】:
我正在尝试检查元素的内部 html 是否为空,但我想在服务器端进行验证,我将 html 视为字符串。这是我的代码
public string HasContent(string htmlString){
// this is the expected value of the htmlString
// <span class="spanArea">
// <STYLE>.ExternalClass234B6D3CB6ED46EEB13945B1427AA47{;}</STYLE>
// </span>
// From this jquery code-------------->
// if($('.spanArea').text().length>0){
//
// }
// <------------------
// I wanted to convert the jquery statement above into c# code.
/// c# code goes here
return htmlSTring;
}
使用这条线
$('.spanArea').text() // what is the equivalent of this line in c#
我会知道 .spanArea 是否真的可以在 ui 中显示某些内容。我想在服务器端进行检查。无需担心如何访问我已经处理过的 DOM。将 htmlString 视为 Html 字符串。
我的问题是在 C# 中这个 jquery 行是否有任何等价物?
提前致谢! :)
【问题讨论】:
-
是的,我想在c#后面的代码中检查spanArea的内部文本是否为空
-
请为您的 AJAX 调用提供服务的页面发布代码。
-
C# 在服务器上运行,它无法直接访问 DOM,因此您唯一的选择是通过添加
runat="server"将所需元素放在服务器端,然后您可以在此处遵循其他建议。 :) -
@Shadow Wizard:不,在计算中总是有第二种选择。
-
@yoda 如果你找到了一种直接使用 C# 代码访问 DOM 元素的方法,那么你就是 yoda! ;)
标签: c# jquery asp.net sharepoint sharepoint-2007