Solved

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

Posted on 2010-08-22
5
574 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

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

12 Experts available now in Live!

Get 1:1 Help Now