交叉放置时不显示目标aspx页面
本文关键字:显示 目标 aspx 页面 | 更新日期: 2023-09-27 18:03:33
我是ASP.NET的新手。我正在尝试网络表单。我有两页:NewOrder。aspx捕获用户的订单,然后交叉放置到SaveOrder。我想保存订单并向用户显示一些信息。
<telerik:RadButton ID="BtnSubmirOrder" runat="server" ButtonType="StandardButton" AutoPostBack="true"
Text="Place order" PostBackUrl="SaveOrder.aspx">
</telerik:RadButton>
当SaveOrder 。加载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();
}
我可以从javascript中看到表单的动作被设置为SaveOrder。当点击Aspx按钮时,为什么浏览器不显示它?
我认为你的浏览器停留在NewOrder上的原因。Aspx是你没有一个按钮点击事件与你的按钮相关联。没有看到你的代码的其余部分,我不知道为什么表单的动作看起来不同。
您可以像下面这样做来引入按钮单击事件。重定向逻辑可以放在那里。
标记:
<telerik:RadButton ID="btnSubmit" runat="server" Text="Place Order"
OnClick="btnSubmit_Click" />
代码: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;
}
}