«
»

Algemeen, ASP.NET, C#, Programmeren, technologie

ASP.NET PostBack madness. Forcing IsPostBack to True

06.05.09 | 2 Comments

So, how do you force IsPostBack to true?  I am goiing to start by spoiling the surprise (if any). Looking at what I found so far : it can’t be done…

Now some context. I am building an automatic object viewer (sortable, searchable item lists + editable property grids) to go with my own little framework. All the code and markup for this is embedded in a separate assembly, and it only requires a HttpModule in the web.config and a few lines of initialization in the global.asax to work.

At the first page call to the structure 2 file are written to the web root. I will call them  A.aspx and A.aspx.cs. The HttpModule will redirect all calls to http://<somedns>/autoadmin/class/<namespace>/<assembly>/<default.aspx or settings.aspx> (which I will now call B.aspx) to A.aspx. The list pages works perfectly, but the property grid pages have post back buttons and that is where the fun starts. The client calls B.aspx which get Transferred to A.aspx which displays the page. I changed the Form action to B.aspx to avoid posting back directly to A.aspx since I need the full url to determine class type etc… Now when the client clicks the a postback button he posts back to B.aspx as I want. The module again transfers this page to A.aspx preserving Querystring and Form. Funny enough nothing happens, the page now executes as if it was called for the first time. In fact the IsPostBack flag is set to false and none of the control event get fired…

Admitted, it wasn’t a big shock, but still, why is this no postback? From the clients point of view its a perfect postback. Sadely the server remembers (viewstate?) that the post form was rendered on A.aspx and not B.aspx. Fair enough, now all I need to do is switch the IsPostBack on manually and I’ll be happy…

Some google-ing let me to the Page.DeterminePostBackMode Method. Its the perfect place to set IsPostBack to false, just override it and return null. Unfortunally, IsPostBack remained false no matter what I returned.  Some more google-ing and some reflection show why that is. In Page.ProcessRequestMain we have the following code

this._requestValueCollection = this.PageAdapter.DeterminePostBackMode(); 

The IsPostBack methods looks like this.  

public bool IsPostBack
{
    get
    {
        if (this._requestValueCollection == null)
        {
            return false;
        }
        if (this._isCrossPagePostBack)
        {
            return true;
        }
        if (this._pageFlags[8])
        {
            return false;
        }
        return (((this.Context.ServerExecuteDepth <= 0) 
                || ((this.Context.Handler != null) 
                && (base.GetType() == this.Context.Handler.GetType()))) 
                && !this._fPageLayoutChanged);
    }
}

Hence DeterminePostBackMode is only usefull for setting IsPostBack to false. The second part won’t help me either since none of my controls are marked to trigger a crosspage postback and the third part can only return false. So that only leaves the last line. And that’s how far I got sofar on this theory hunt. 

If I can influence the last line I may still be possible to force IsPostBack to true. I will continue my search one of the coming days. (For now I have a simple work around but I really want to know if it can be done).

Once out figure out the last a write a new post. Meanwhile, if anyone has more insight or knows how to do it let me know.


2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

:

:


«
»

My Index

0-10

A

Adwords campagne beheer

B

bakgerei voor kindjes

C

CE HTML
Community Server

D

E

Elegant
Elegant opinie

F

Familie Anrijs
fotoshoot
professionele familiereportage
fotoshoot
familie fotoshoot
FrontierVille
FrontierVille guides review site

G

GarageTV
garagetv.be
Google Adwords - adverteren op zoekmachines
Google-approved Qualified Professional
Groene stroom

H

huwelijksreportage

I

Internet reclame

J

JWI Consulting

K

Kantoorinrichting
Kaartjes bestellen
kerstkaartjes bestellen
KMO website snelheidstest

L

Lamineerapparaat a3

M

N

O

Online kaartjes bestellen

P

P&O ferries
Philips Net TV
Playmobilkasteel
Portfolio Development (.NET C# PHP)
Portfolio SEO (Search Engine Optimalisatie)
Provinciaal Voetbal
provinciaal voetbal Antwerpen
provinciaal voetbal Branbant
provinciaal voetbal Limburg
provinciaal voetbal Oost-Vlaanderen
provinciaal voetbal West-Vlaanderen

Q

R

S

SEO (Search Engine Optimization)
Snelheids voor kmo websites
Suikerpasta

T

trouwfoto's
trouwfoto's

U

www.uwfotomoment.be

V

verjaardagsfeestjes
Verjaardagsfeestjes voor kindjes
Voetbal uitslagen
online voetbalschoenen kopen

W

google webmaster tools

X

Y

Z

Zoekmachine optimalisatie