[英]Unable to access div content from C#
I only see the space tags "\\r\\n "\\r\\n"
for InnerHTML & InnerText properties and not the actual content. Where am i going wrong 我只看到InnerHTML和InnerText属性的空格标签
"\\r\\n "\\r\\n"
,而不是实际内容。我在哪里错了
RENDERED HTML: 渲染HTML:
<div id="urllist" runat="server">
http://test1t.com
<br></br>
http://test2.com
<br></br>
</div>
C#: C#:
HtmlContainerControl list = (HtmlContainerControl)urllist;
string string1 = list.InnerHtml;
string string2 = list.InnerText;
//this didnt work either
string string1 = urllist.InnerHtml;
string string2 = urllist.InnerText;
If i remember correctly you have to use Controls[0]
to find the literal control that contains the text: 如果我没记错的话,您必须使用
Controls[0]
查找包含文本的文字控件:
var div = (HtmlGenericControl) urllist;
var lit = (LiteralControl) div.Controls[0];
string text = lit.Text;
Update : tested, it works. 更新 :已测试,可以正常工作。 This is
text
: 这是
text
:
http://test1t.com
<br></br>
http://test2.com
<br></br>
However, now i have tested it with your approach and it works also. 但是,现在我已经用您的方法对其进行了测试,它也可以工作。
I would have added a comment, but I cannot add images in comments. 我本来可以添加评论,但是不能在评论中添加图像。 See below, I've tested your code and it works:
见下文,我已经测试了您的代码,它可以正常工作:
Are you sure you don't check your result in a HTML page or that you are not altering your result in any way before you check it? 您确定不检查HTML页面中的结果还是在检查结果前不以任何方式更改结果?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.