Is there a way to force Response.Redirect or Server.Transfer methods of the Page class to change "IsPostBack" to true?
Basically, I'm trying to circumvent making a form submit to another page because every time I do, I receive the error "Validation of Viewstate MAC failed" (which seems to be a common problem for people running server farms, but I'm just running it on a simple
webserver)
If anyone has any advice on how to accomplish either of these, I would greatly appreciate it.
Ispostback can only be set by a page posting back to itself (hence the name). For scenarios like yours, cross-page postback was introduced in asp.net 2. You may want to try it.
Well, I tried this in both pages and still receive the error.
hooligannes97, can I use this in conjunction with Response.Redirect and/or Server.Transfer? I could have sworn I gave that a shot, but that variable never changed...
Brian, a redirect is not a postback, it's a redirect. [;)]
If you use Transfer or a crosspage postback, this information will help you understand how to get the correct postback value you are looking for (From a
post at Dino Esposito's Blog):
This code never worked as expected, in Beta 1 as well as in Beta 2. Recently, I realized it was my fault as
IsCrossPagePostBack is designed to return true for the PreviousPage page object, not for the current page. In other words, it returns true for the page which STARTED a cross-page posting, not for the page being invoked that
way
Complementarily, please scroll all the way down to
this page in MSDN to find the following explanation about Cross-Page Posting versus Server.Transfer:
<div class=subsection>
The PreviousPage property and the
PreviousPageType directive are useful in two situations where you invoke the target page: in a cross-page postback, which is a client-based transfer, and with the
Transfer method, which is a server-based operation. In both operations, code
in the target page can get a reference to the source page using the PreviousPage
property.
Sorry, I know I can be a bit thick at times, but do you think you could tell me why this wouldn't work if I changed the code to use Server.Transfer on the source page and the following code on the target page? I just tried this configuration and IsCrossPagePostBack
always returns false.
if (PreviousPage != null)
{
if (PreviousPage.IsCrossPagePostBack == true)
{
newItems = null;
}
}
brianwolfe86
Member
7 Points
50 Posts
Response.Redirect or Server.Transfer to force IsPostBack
Dec 16, 2008 10:02 PM|LINK
Hi,
Is there a way to force Response.Redirect or Server.Transfer methods of the Page class to change "IsPostBack" to true?
Basically, I'm trying to circumvent making a form submit to another page because every time I do, I receive the error "Validation of Viewstate MAC failed" (which seems to be a common problem for people running server farms, but I'm just running it on a simple webserver)
If anyone has any advice on how to accomplish either of these, I would greatly appreciate it.
Let me know if you need to see my code.
Thanks,
Brian
hooligannes9...
All-Star
16504 Points
2917 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 16, 2008 10:40 PM|LINK
Ispostback can only be set by a page posting back to itself (hence the name). For scenarios like yours, cross-page postback was introduced in asp.net 2. You may want to try it.
retroviz
Participant
898 Points
249 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 16, 2008 10:42 PM|LINK
Do you get this on both Response.Redirect and Server.Transfer?
You can set at your Page attributes:
EnableViewStateMac="false"
Which would prevent asp.net performing the viewstate check for cross posting between pages.
Hope that helps,
Ben
brianwolfe86
Member
7 Points
50 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 18, 2008 03:05 PM|LINK
Well, I tried this in both pages and still receive the error.
hooligannes97, can I use this in conjunction with Response.Redirect and/or Server.Transfer? I could have sworn I gave that a shot, but that variable never changed...
brianwolfe86
Member
7 Points
50 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 18, 2008 03:16 PM|LINK
I just tested this and the IsCrossPagePostBack always returns false no matter if I transfer from another page or if I refresh.
Any idea why this might be?
For reference, here's how I'm transferring the page:
Response.Redirect("cart.aspx");hooligannes9...
All-Star
16504 Points
2917 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 18, 2008 10:54 PM|LINK
Brian, a redirect is not a postback, it's a redirect. [;)]
If you use Transfer or a crosspage postback, this information will help you understand how to get the correct postback value you are looking for (From a post at Dino Esposito's Blog):
This code never worked as expected, in Beta 1 as well as in Beta 2. Recently, I realized it was my fault as IsCrossPagePostBack is designed to return true for the PreviousPage page object, not for the current page. In other words, it returns true for the page which STARTED a cross-page posting, not for the page being invoked that way
Complementarily, please scroll all the way down to this page in MSDN to find the following explanation about Cross-Page Posting versus Server.Transfer: <div class=subsection>The PreviousPage property and the PreviousPageType directive are useful in two situations where you invoke the target page: in a cross-page postback, which is a client-based transfer, and with the Transfer method, which is a server-based operation. In both operations, code in the target page can get a reference to the source page using the PreviousPage property.
It might be important in the target page to determine whether the page was invoked from a cross-page posting or a Server.Transfer operation. To help you do this, the Page class exposes a property named IsCrossPagePostBack. For details, see How to: Determine How ASP.NET Web Pages Were Invoked.
</div>brianwolfe86
Member
7 Points
50 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 18, 2008 11:21 PM|LINK
Sorry, I know I can be a bit thick at times, but do you think you could tell me why this wouldn't work if I changed the code to use Server.Transfer on the source page and the following code on the target page? I just tried this configuration and IsCrossPagePostBack always returns false.
if (PreviousPage != null) { if (PreviousPage.IsCrossPagePostBack == true) { newItems = null; } }Thanks again,
Brian
<div style="border-style: solid; border-color: black; border-width: 0px 0px 0px 1px; width: 460px; height: 100%; top: 0px; right: 0px; padding-left: 0px; position: fixed; background-color: white; z-index: 1000; display: none;"><div style="border: 0px none ; top: 1px; width: 100%; height: 42px; position: absolute;"><form onsubmit="return false"><div style="position: absolute; left: 2px; right: 0px;"><input id="LIU_txt" style="border: 1px solid black; margin: 0pt; padding: 0pt; position: absolute; left: 0px; right: 240px; font-size: 14px ! important; height: 17px ! important; line-height: 50px; display: block;"><input id="LIU_search" style="border: 1px solid black; padding: 0pt; position: absolute; width: 68px; right: 68px; font-size: 14px ! important; height: 19px;" value="Search" type="submit"><button id="LIU_prev" style="border: 1px solid black; padding: 0pt; position: absolute; width: 20px; right: 46px; height: 19px;"><</button><button id="LIU_next" style="border: 1px solid black; padding: 0pt; position: absolute; width: 20px; right: 24px; height: 19px;">></button><button id="LIU_mode" style="border: 1px solid black; padding: 0pt; position: absolute; width: 20px; right: 2px; height: 19px;">0</button></div><div style="position: absolute; left: 0px; right: 0px; top: 40px; width: 100%; height: 1px; background-color: black;"></div><div style="position: absolute; left: 2px; right: 0px; top: 22px;"><button id="LIU_0" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">w</button><button id="LIU_1" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">v</button><button id="LIU_2" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">c</button><button id="LIU_3" style="border-style: solid; border-color: black black white; border-width: 1px; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: white;">i</button><button id="LIU_4" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">d</button><button id="LIU_5" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">f</button><button id="LIU_6" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">j</button><button id="LIU_7" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">o</button><button id="LIU_8" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">g</button><button id="LIU_9" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">u</button><button id="LIU_10" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">a</button><button id="LIU_11" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">r</button><button id="LIU_12" style="border: 1px solid black; padding: 0pt; width: 20px; margin-right: 2px; height: 19px; background-color: rgb(221, 221, 221);">m</button></div></form></div></div>brianwolfe86
Member
7 Points
50 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 19, 2008 02:05 PM|LINK
Anyone? I would really appreciate the help as this is very urgent.
Thanks,
Brian
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 19, 2008 02:32 PM|LINK
This error occurs when u a viewstate from source page is passed to destination page. for more details read my post on viewstate
http://forums.asp.net/p/1362739/2819383.aspx#2819383
Contact me
brianwolfe86
Member
7 Points
50 Posts
Re: Response.Redirect or Server.Transfer to force IsPostBack
Dec 19, 2008 04:22 PM|LINK
I changed my page directive on my destination page to read as follows:
And my transfer code on my source page reads like this: