【发布时间】:2014-12-05 12:01:18
【问题描述】:
我有一个名为“txtNewSubComment”的 asp TextBox 控件。但是,因为我动态生成多个相同的文本框,所以我需要一种方法来保持它们的唯一性,以便我可以引用它们。我正在尝试执行以下操作:
<asp:TextBox ID="txtNewSubComment_<%=comment.Id %>" />(不是整个代码块,但你明白了)
comment.Id 将返回与该 TextBox 控件相关的唯一 int。我的问题是 aspx 似乎没有将内联代码 () 读取为内联代码,而是将其读取为 aspx。因此,它不是在 html 中呈现为txtNewSubComment_1(如果我设法到达那个阶段而没有错误妨碍的话),而是呈现为txtNewSubComment_<%=comment.Id%>
我在尝试为按钮传递 CommandArgument 时遇到问题
文本框是通过 aspx 标记中的以下代码生成的:
<% Site.BO.Comment[] commentList = db.GetAllCommentsForImage(CurrentImage.Id);
if (commentList.Count() > 0)
{
foreach (Site.BO.Comment comment in commentList.OrderByDescending(x => x.LastUpdated))
{
Site.BO.Profile commenterProfile = db.ProfileGet(comment.User.Id); %>
<asp:TextBox ID="txtNewSubComment_<%=comment.Id %>" runat="server" TextMode="MultiLine"></asp:TextBox>
<% } } %>
【问题讨论】:
-
你是如何动态创建它们的?它们在中继器/网格中吗?
-
它们是在 aspx 代码中的 foreach 循环中生成的。
-
是否可以将它们放在中继器中,您将为自己省去很多麻烦。
-
用
runat="server"装饰它 -
有什么想法吗? OP 已更新。