[英]ASP form parameter names being changed to include the master page contentplaceholder
Here is my page: 这是我的页面:
<%@ Page Language="C#" MasterPageFile="~/FBMaster.master" CodeFile="ViewOffer.aspx.cs" Inherits="ViewOffer" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%
FlightBookingWS.FlightBookingSoapClient client = new FlightBookingWS.FlightBookingSoapClient();
FlightBookingWS.Offer offer = client.GetOffer(Request.Form["OfferID"]);
if (offer != null)
{
%>
<div class="OfferDiv">
<span><b>Origin Airport: </b><%=offer.OriginAirport ?? "" %></span>
<span><b>Destination Airport: </b><%=offer.DestinationAirport ?? "" %></span>
<span><b>Airline: </b><%=offer.Airline ?? ""%></span>
<span><b>Available Seats: </b><%=offer.AvailableSeats%></span>
<span><b>Number Of Connections: </b><%=offer.NumberOfConnections%></span>
<%
if (offer.Fare != null)
{
%>
<span><b>Fare: </b><%=String.Format("{0:0.00} {1}", offer.Fare.Value, offer.Fare.Currency) %></span>
<form runat="server">
<span>
<input type="hidden" id="OfferIDField" runat="server" />
<input type="hidden" id="MessageField" runat="server" />
<b>Number of Seats: </b>
<asp:TextBox ID="NumSeatsField" runat="server" Text="1" />
<asp:Button runat="server" Text="Book now" />
</span>
</form>
<%
}
}
else
{
%>
Offer not found.
<%
}
%>
<div id="ErrorBox" runat="server"></div>
</div>
</asp:Content>
Whenever I submit the form, the keys used in the post data are changed from the IDs I wrote to the following ones: 每当我提交表单时,帖子数据中使用的密钥就会从我写的ID更改为以下ID:
Ideally I'd like to access them using the same keys as the IDs of the input
s they came from, like in normal HTML. 理想情况下,我想使用与input
ID相同的键来访问它们,就像在普通HTML中一样。
When you put markup on a page with the runat="server"
attribute, you are not actually writing page markup. 当您将标记放在带有runat="server"
属性的页面上时,实际上并不是在写页面标记。 You are defining server-side controls that emit page markup. 您正在定义发出页面标记的服务器端控件。 You're not meant to use them like actual HTML elements. 您无意像实际的HTML元素一样使用它们。
When the page is posted back, the ASP.NET framework looks at the request message and parses all of the values. 页面回发后,ASP.NET框架将查看请求消息并解析所有值。 It then populates the server-side controls with the necessary data so you can retrieve it easily using ASP.NET syntax. 然后,它将用必要的数据填充服务器端控件,以便您可以使用ASP.NET语法轻松地检索它。
So, instead of 所以,代替
var offerID = Request.Form["ctl100$ContentPlaceHolder1#OfferIDField"]
you should simply use 你应该简单地使用
var offerID = this.OfferID.Text;
This is the way ASP.NET web forms work. 这就是ASP.NET Web表单的工作方式。
If you'd rather do it the old-fashioned way, remove the runat="server"
attribute and write your markup like regular HTML: 如果您希望采用老式的方法,请删除runat="server"
属性,并像常规HTML一样编写标记:
<INPUT ID="OfferID" Name="OfferID">
...and then you can read it the "normal" way: ...然后您可以按“正常”方式阅读它:
var offerID = Request.Form["OfferID"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.