Solved

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

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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