Force A PostBack VIA ASP Code

Posted on 2009-04-21
Medium Priority
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
  • 2
  • 2
LVL 14

Expert Comment

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

Author Comment

by:Ben Santiardo
ID: 24197157
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

ID: 24197299

I know only in Asp.net. 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

Ben Santiardo earned 0 total points
ID: 24316177
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

809 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