【发布时间】:2015-05-08 08:28:36
【问题描述】:
我的 .aspx 文件中有以下 sn-p 代码,我希望按钮将 ID 发送到后面的代码。
<%List<Notes> CommentsList = FindNotes(ParentNote.ID); %>
<%foreach (var comment in CommentsList) { %>
<div id="note" class="tierTwo"><p><%: comment.Content %></p><ul><li><%: comment.AddedDate %></li><li>20:29</li><li><%: comment.AddedByName %></li><li><a href="#" onclick="showAddComment(addComment<%:comment.NoteID%>)" class="but">Add comment</a></li></ul> >
<div id="addComment<%:comment.NoteID%>" class="tierOne" style="display:none">
<asp:TextBox ID="commentreplytext" runat="server" rows="4"> </asp:TextBox>
<asp:HiddenField id="ParentIdReply" value='<%=comment.NoteID%>' runat="server" />
<asp:Button ID="Button2" runat="server" Text="Add" CommandArgument="<%: comment.NoteID%>" OnCommand="Add_Comment" />
</div>
</div>
目前后面的代码是这样的
protected void Add_Comment(object sender, CommandEventArgs e)
{
string uniqueNoteID = e.CommandArgument.ToString();
}
命令参数被发送到 Add_Comment 方法,但它返回“”而不是它所代表的值。在设置 div id 时,这种检索 NoteID 值的方法可以正常工作,所以我不知道为什么它会导致 commandArgument 出现问题。
【问题讨论】:
-
你为什么要这样?您可以在 ,cs 页面上使用中继器和绑定数据。
标签: c# asp.net button commandargument