gpt4 book ai didi

ASP.Net 添加控件 "Cannot get inner content of [control] because the contents are not literal."

转载 作者:行者123 更新时间:2023-12-04 21:27:11 27 4
gpt4 key购买 nike

我目前正在尝试在我的 Web 表单中动态添加 HTML 控件,但是每次我在另一个控件中插入一个控件时都会出现错误 Cannot get inner content of [control] because the contents are not literal弹出(尝试查看innerHtml 或innerText 时)并且似乎无法找到原因。

这是我正在使用的代码:

Dim newsList As New HtmlControls.HtmlGenericControl
newsList.TagName = "ul"
Dim i As Integer = 0
For Each newsDR As DataRow In newDS.Tables(0).Rows
i += 1
Dim stri As String = i.ToString()
Dim newsListItem As New HtmlControls.HtmlGenericControl
newsListItem.TagName = "li"
newsListItem.ID = "newsListItem" + stri

Dim newsTitle As New HtmlControls.HtmlGenericControl
newsTitle.TagName = "h1"
newsTitle.ID = "newsTitle" + stri
Dim newsAnchor As New HtmlControls.HtmlAnchor
newsAnchor.ID = "newsAnchor" + stri
newsAnchor.InnerHtml = newsDR("NewsTitle")
newsAnchor.HRef = "#"

newsTitle.Controls.Add(newsAnchor)

Dim newsSummary As New HtmlControls.HtmlGenericControl
newsSummary.TagName = "div"
newsSummary.ID = "newsSummary" + stri
newsSummary.InnerHtml = newsDR("NewsSummary")

newsListItem.Controls.Add(newsTitle)
newsListItem.Controls.Add(newsSummary)
newsList.Controls.Add(newsListItem)
Next

最佳答案

渲染控件后不应使用 innerHtml,而应使用 RenderControl,如下所述:

http://forums.asp.net/t/1168614.aspx

关于ASP.Net 添加控件 "Cannot get inner content of [control] because the contents are not literal.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1433500/

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