< asp:Button>中PostBackUrl的目的 [英] Purpose of PostBackUrl in <asp:Button>

查看:70
本文介绍了< asp:Button>中PostBackUrl的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 PostBackUrl 的目的是什么?
假设我在 Cart.aspx 中有一个 button :

What's the purpose of using PostBackUrl?
Let's say I have a button which is in Cart.aspx:

 <asp:Button ID="btnContinue" runat="server" Text="Continue Shopping" PostBackUrl="~/Order.aspx"  CssClass="btn" />

这意味着我将被重定向到 Order.aspx ,而不是停留在原始的 Cart.aspx 上.这是我的两个问题:

That means that I will be redirectd to Order.aspx, rather than staying on original Cart.aspx. Here are my two questions:

  1. 我在 Cart.aspx 中也有一个 TextBox .
    当我单击 button 时, TextBox 的值将被发布回 Order.aspx ,而不是原始的 Cart.aspx .现在,我认为我们只有将它发布回包含此 TextBox Cart.aspx 时,才能获得该值.
    如果我想在新页面上检索此值怎么办?

  1. I also have a TextBox in Cart.aspx.
    When I click the button, the value of the TextBox will be posted back to Order.aspx rather than original Cart.aspx. Now I think we can only get this value if it is posted back to Cart.aspx, which contains this TextBox.
    What if I want to retrieve this value on the new page?

如果无法检索 Cart.aspx 上的任何输入,为什么我们需要使用 PostBackUrl ?我们可以添加:

If there is no way to retrieve any input on Cart.aspx, why do we need to use PostBackUrl? We could just add:

Response.Redirect(〜/Order.aspx") Cart.aspx.cs ?

推荐答案

如果您未指定条目 PostBackUrl ,则按钮会将数据提交回同一页面,在这种情况下, cart.aspx .

If you do not specify the entry PostBackUrl, the button will submit the data back to the same page, in your case it is cart.aspx.

PostBackUrl 的目的是对数据进行跨页发布.

The purpose of PostBackUrl is a across-page-posting of data.

如果您指定 PostBackUrl =〜/Order.aspx" ,您的数据将被发布回您的 Order.aspx 页面.在 Order.aspx 页面中,您将能够使用以下命令获取 TextBox (位于 cart.aspx 中)数据:

If you specify PostBackUrl="~/Order.aspx", your data will be posted back to your Order.aspx page. In your Order.aspx page, you will be able to get your TextBox (which was in cart.aspx) data using:

Page.PreviousPage.FindControl("TextBox1")

您可以在 https://msdn.microsoft.com/上了解更多信息.zh-CN/library/ms178139.aspx

这篇关于&lt; asp:Button&gt;中PostBackUrl的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆