Solved

How to refresh the ASP.Net page after asynchronously updating the contents of page.

Posted on 2010-08-22
5
575 Views
Last Modified: 2013-12-17

Hi Experts,

         I am working on a ASP.Net web application wherein I am calling a class method Asynchronously to get the data from data base (using AsyncCallback) on page load. after the completion of this callback method raises an event. I'm handling the event on the asp.net page wherein I'm assigning the datasource to a grid view. Everything is going good except for the page is not getting refreshed after the event is getting fired. I have checked the datasource of the grid is assigned properly but the contents are not shown on the page.

My question is what can I do to refresh the contents of the page.


Please help its Urgent

Thanks and Regards
Paramhans
0
Comment
Question by:ParamhansDubey
5 Comments
 
LVL 16

Expert Comment

by:Stephan
ID: 33498755
Not sure if you mean that your data you have attached to the gridview needs to be refreshed, or the entire page.

If the first one: try GridView.DataBind();
0
 

Author Comment

by:ParamhansDubey
ID: 33499194
As I mentioned I'm calling the method Asynchronously so after the event is fired and after assigning the data source to the grid and after data binding it i want to post back the page to the server so that the latest contents of the page are visible on the page. I want to refresh the entire page on that event.
0
 
LVL 2

Expert Comment

by:SandyAgo
ID: 33500289
This is not possible. What you are trying to do is access the browser from the server side after the Page has already loaded. This cannot be done without some client initiation.

So, the code behind model is not really suitable for your purpose. However, an ugly way to do this would to be make the class method you are calling set a flag to define when it is finished, it will have to be on a per request/ session/ or global basis whichever suits your needs. Then put your GridView in an UpdatePanel, hide a Button on the page which causes an AsyncPostback after the page loads and inside the Button_Click method, make your PostBack wait until the data is loaded then call updatePanelName.Update() and complete the postback. Also make sure you dont start loading the data again duiring the postback.
0
 
LVL 3

Accepted Solution

by:
raaziq earned 500 total points
ID: 33540681
try adding this script for auto refresh based on a particular interval..

 <script>
        //AutoRefresh();
        AutoRefresh1();
        var parselimit
        function AutoRefresh1() {
            var limit = "0:45"

            if (document.images) {
                parselimit = limit.split(":")
                parselimit = parselimit[0] * 60 + parselimit[1] * 1
            }

            window.onload = beginrefresh1
        }

        function beginrefresh1() {
            if (!document.images)
                return
            if (parselimit == 1) {
                __doPostBack('Auto_Refresh', '');
            }
            else {
                parselimit -= 1
                curmin = Math.floor(parselimit / 60)
                cursec = parselimit % 60
                if (curmin != 0)
                    curtime = "Page will auto refresh in " + curmin + " minutes and " + cursec + " seconds!"
                else
                    curtime = "Page will auto refresh in " + cursec + " seconds!"
                window.status = curtime
                setTimeout("beginrefresh1()", 1000)
            }
        }
    </script>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

21 Experts available now in Live!

Get 1:1 Help Now