我想调用另一个 ASP 页面并传递一个参数 (entry.ID)。
我有一个像这样的 Master-Page Global.master(我只会发布部分代码):
<body>
<div id="global" style="height:2000px;">
<form runat="server" id="globalForm">
<div id="body">
<asp:ContentPlaceHolder ID="mainContentPlaceHolder" runat="server">
<div id="mainContent">
</div>
</asp:ContentPlaceHolder>
</div>
</form>
</div>
和一个使用母版页的 Default.aspx 页面:
<asp:Content ID="Content1" ContentPlaceHolderID="mainContentPlaceHolder" runat="Server">
<div id="mainContent">
<% ICollection<Database.Blogentry> entries;
entries = Database.BlogentryDBO.Instance.getAllBlogentries();
foreach (Database.Blogentry entry in entries) { %>
<div class="blogEntryBody">
<div class="blogEntryText">
<%= entry.Content %>
</div>
</div>
<div class="blogEntryFooter">
<span class="blogEntryView">
<%--CALL HERE ANOTHER PAGE WITH A BUTTON AND PASS THE PARAMETER entry.ID-->
</span>
</div>
<%
}
%>
</div>
我已经尝试过了
<label visible="false" id="LabelEntryId" name="LabelEntryId"><%= entry.ID %></label>
<asp:button ID="Button2" runat="server" class="buttonBlogEntry" text="view more ..." onclick="viewEntireBlog_onclick" CommandArgument='<%# Eval("LabelEntryId")%>' />
但是我在 onClick 方法中没有 CommandEventArgs 元素,只有一个 EventArgs 元素,所以我无法访问我的 CommandArgument ?!
并使用
<input runat="server" type="text" id="LabelEntryId" value="<%= entry.ID %>" visible="false"/>
然后访问代码隐藏中的 input-element 也是不可能的,因为由于循环,我有多个 LabelEntryId-Input。
另一个想法是做这样的事情
<asp:button ID="Button1" runat="server" class="buttonBlogEntry" text="view more ..." onclick="<%= Response.Redirect("BlogEntrySortedByCategory.aspx?entryID=" + entry.ID); %>"/>
但我不知道该怎么做...
你能帮帮我吗?
最佳答案
您尝试过使用标准 a 标签吗?
<a href='/someotherpage.aspx?entryid=<%= entry.Id %>'>View more</a>
关于c# - 在 ASP.NET C# 中使用不同的参数动态调用另一个 ASP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22578848/