[英]target aspx page is not displayed when crossposting
I am new to ASP.NET. 我是ASP.NET的新手。 I am experimenting with webforms.
我正在尝试使用Webforms。 I have 2 pages: NewOrder.aspx which captures the user's order and then crossposts to SaveOrder.aspx where I want to save the order and display some information back to the user.
我有2页:NewOrder.aspx,它捕获用户的订单,然后交叉张贴到SaveOrder.aspx,我要在其中保存订单并向用户显示一些信息。
<telerik:RadButton ID="BtnSubmirOrder" runat="server" ButtonType="StandardButton" AutoPostBack="true"
Text="Place order" PostBackUrl="SaveOrder.aspx">
</telerik:RadButton>
When SaveOrder.aspx is loaded, the code below sets its control values and saves the order. 加载SaveOrder.aspx时,以下代码设置其控制值并保存订单。 however the browser stays at NewOrder.aspx.
但是浏览器仍位于NewOrder.aspx。
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage==null || !PreviousPage.IsCrossPagePostBack)
Response.Redirect("~/Default.aspx");
var referencingPage = PreviousPage as NewOrder;
int id = Int32.Parse(referencingPage.SelectedPublicationId);
DateTime neededBy = referencingPage.SelectedOrderDate;
LblSummaryIsbn.Text = referencingPage.SelectedIsbn;
LblSummaryNbrCopies.Text = referencingPage.NbrOfOrderedCopies;
DateTime orderDate = DateTime.Now;
LblSummaryOrderDate.Text = orderDate.ToShortDateString();
LblSummaryTitle.Text = referencingPage.SelectedPublicationTitle;
int quantity = Int32.Parse(referencingPage.NbrOfOrderedCopies);
StockContainer _context = new StockContainer();
Order newOrder = Order.CreateOrder(orderDate, quantity, neededBy, id);
_context.Orders.AddObject(newOrder);
_context.SaveChanges();
}
I can see from the javascript that the form's action is set to SaveOrder.aspx when the button is clicked so why is the browser not displaying it? 我可以从javascript中看到,单击按钮时,表单的操作设置为SaveOrder.aspx,为什么浏览器不显示它?
I think the reason your browser is staying on NewOrder.aspx is that you don't have a button click event associated with your button. 我认为您的浏览器停留在NewOrder.aspx上的原因是您没有与按钮相关联的按钮单击事件。 Without seeing the rest of your code, I'm not sure why the form's action appears different.
没有看到其余的代码,我不确定为什么表单的动作看起来与众不同。
You could do something like the following to introduce a button click event. 您可以执行以下操作来引入按钮单击事件。 The redirect logic could go in there.
重定向逻辑可以放入其中。
Markup: 标记:
<telerik:RadButton ID="btnSubmit" runat="server" Text="Place Order"
OnClick="btnSubmit_Click" />
Code: 码:
public class NameOfPage
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
// You could do validation here and display an error message if something is not right.
// For simplicity I am assuming the data comes from a set of textboxes.
if (!PageIsValid())
{
return;
}
StockContainer _context = new StockContainer();
Order newOrder = Order.CreateOrder(txtOrderDate.Text, txtQuantity.Text, txtNeededBy.Text, id);
_context.Orders.AddObject(newOrder);
_context.SaveChanges();
// Add your redirect logic here.
}
private bool PageIsValid()
{
if (string.IsNullOrEmpty(txtOrderDate.Text))
{
return false;
}
if (string.IsNullOrEmpty(txtQuantity.Text))
{
return false;
}
// and so on for the other fields that are required.
return true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.