开发者

Cross-Page Posting with a Master Page

开发者 https://www.devze.com 2023-01-24 16:20 出处:网络
I found a workaround for my specific need, but I thought I\'d ask this question anyway. Say I have a typical data entry web proje开发者_如何学运维ct with a master page -- instead of using the Session

I found a workaround for my specific need, but I thought I'd ask this question anyway.

Say I have a typical data entry web proje开发者_如何学运维ct with a master page -- instead of using the Session variable and using Response.Redirect or Server.Transfer to redirect users who are part of the way through data entry to the next step, I'd rather use cross-page posting.

I tried setting up one of my websites in this manner, with a button like:

<asp:Button ID="next" text="next" runat="server" PostBackUrl="EnterInfo.aspx" />

When I went to test the changes, my <form> tag hadn't changed at all:

<form id="aspnetForm" action="SelectUser.aspx" method="post" name="aspnetForm">

Did I miss any details here, or is cross-page posting simply not intended for use with a master page?

Edit: The form tag above is the tag as rendered on the client -- not the server-side tag. I've read MSDN articles (like this one) that seem to me to explicitly state that cross page posting actually posts the form to another page.

Perhaps I've misinterpreted this as changing the form's action, but regardless my source form does not post invoke anything anywhere on my target when I click the button I altered -- it merely posts back to the current page.


I don't think using the PostBackUrl attribute will change the action of the form in the markup, as there could be many other controls just doing a normal postback. I imagine that some javascript is used to change the action of the form when this particular button is pressed.


You need to place a declaration on the second page where data come from.

So you have:

PostBackUrl="EnterInfo.aspx"

On EnterInfo.aspx you declare where you can get informations

<%@ PreviousPageType VirtualPath="~/SelectedUser.aspx" %>

and you get them by...

if (Page.PreviousPage != null)
{
    if(Page.PreviousPage.IsCrossPagePostBack == true)
    {
        GetTheClass = PreviousPage.MyDataClass;
    }
}

The PostBackUrl not change the form url.

Some reference.
ASP.NET how to access public properties?

Cross-page postbacks and back again retaining data from source page

Ps At first I was thinking that you have just type what you see at render, but if not the case As @Mystere point out you need to run this inside an asp.net form.


First, as Graham says.. PostBackUrl does not change the postback action. Second, you can only use PostBackUrl on an asp.net enabled form, which means the form must have runat="server"

0

精彩评论

暂无评论...
验证码 换一张
取 消