Force A PostBack VIA ASP Code

Posted on 2009-04-21
Last Modified: 2013-11-07
I have some code that runs on a PostBack event.  If during this PostBack a certain situation is found, the code displays a hidden panel at the end of the PostBack run which has an animated gif.  

This animation should run while some new code (which can be time consuming) runs.  Problem is, that if I run this time consuming code within the same PostBack operation in the 1st paragraph, the current page (reloaded with the unhidden panel) hasn't yet shown itself, so the user doesn't see the panel and animation yet.

What I would like to be able to do, is have the current PostBack operation finish building the page with the new unhidden panel so that it displays to the use.  Then somehow tell the system to perform another "forced" PostBack immediatly after, in which I have code that checks to see if this panel is visible, if it is then the time consuming peice of code is run.

Is there anyway to do this?
Question by:Ben Santiardo
    LVL 14

    Expert Comment

    Do you wan't to force a postback using javascript?

    Author Comment

    by:Ben Santiardo
    Being that JavaScript is ClientSide ... I don't know if that will be able to do what I need.  But if I can get it to work VIA JavaScript, then sure.  As long as I can get it to work, I don't care whether it's ASP or JSP.  :-)
    LVL 14

    Expert Comment


    I know only in For example if you want to force postback of a LinkButton from client side, then what you have to do is

    <script type="text/javascript">
    <%=Page.ClientScript.GetPostBackClientHyperlink(lb, string.Empty)%>;

    Since you are invoking an event of a control using a script, you need to register the event for validation using

    Page.ClientScript.RegisterForEventValidation(lb.UniqueID, string.Empty);

    Accepted Solution

    Ok, since I figured this out (in a round-about way) on my own, I figured i'd post my results in case anyone else is curious about how to do this.
    Since there is no way to force a PostBack directly through ASP code, what I did was create a method on my page that added a "Refresh Timer" on my page using META TAGS.  The method allows for any designated amount of second, but I used 2 seconds for the purposes of this specific issue.  
    Next I created a class that I was able to store in a Session Variable, this class was specially designed to store my own custom variables in one centralized location, I called the class HiddenPostData.  
    Now, in my pages Load() method, I checked to see if the SessionVariable has data inside the HiddenPostData control...if it does, then that means that even though the page was loaded normally (not using POST), I still want to treat it as if it was POSTED. So I used the information that I sent VIA the HiddenPostData Class, which holds all the relevant POST data I need the page to have.  When I am done loading, I clear the HiddenPostData Class so that this (or other) pages do not mistakenly use it as well.
    It's a bit convoluted I know, but it works, which is the biggest thing.  I hope this helps anyone else looking for a solution to this type of situation.
    Note: The above explanation sounds complex, and it is, but was made much simpler to use because I incorporated it into my MasterPages and PageTemplate classes so all pages have access to this methodology.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now