简体   繁体   English

交叉发布时不显示目标aspx页面

[英]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.

相关问题 显示CrossPage1.aspx时,必须在列表框中具有相同的选择,然后才能仍然选择转移到CrossPage2页面 - When the CrossPage1.aspx is displayed, I need to have same selection in the listbox before transferring to CrossPage2 page must still be selected 从aspx页上显示的本地文本文件替换标签 - Replacing Tags from local text file displayed on aspx page 何时使用javascript而不是创建aspx页面? - When to use javascript instead of creating an aspx page? 在aspx页面中打开Crystal Report时出错 - Error when opening crystal report in aspx page 将数据从ASPX发布到ASP页面时删除了空格,但是在发布到ASPX页面时保留了空格 - Spaces being removed when posting data from ASPX to ASP page, but spaces preserved when posting to ASPX page Sharepoint 2010的aspx页面中的长时间运行任务在浏览器中显示“页面无法显示” - Long running tasks in aspx page on Sharepoint 2010 shows “Page cannot be displayed” in browser 如何正确计算将在“确认aspx”页面上显示的NoOfDays标签? - How can I calculate the NoOfDays label correctly that will be displayed on the Confirm aspx page? 如何调试aspx页面,不断出现错误时找不到页面 - How to debug an aspx page, keeps saying page not found when there is an error aspx页面作为页面的参数 - aspx page as an argument to a page 在span标签内使用类时,aspx页面出现错误 - Error in aspx page when using class inside of span tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM