0

I have a C# custom webpart in sharepoint 2013, display listview from a document library. This library will be updated if we submit a form. I want to update this Webpart each x time. Here is my code:

tCell.InnerHtml=@"...";
tRow.Cells.Add(tCell); Table.Rows.Add(tRow);
0

your code doesnt show anything todo with the timer itself, just adding some data to cell...

1) bind the list through your code to a table or what ever container your using, like splistview:

http://www.codeproject.com/Articles/42399/DataBinding-to-SPListItemCollection

2) now create the timer on the page within code behind to refresh the page x ammount of times:

http://msdn.microsoft.com/en-gb/library/cc295400.aspx

and

https://www.asp.net/ajax/documentation/live/overview/UsingTimerControlTutorial.aspx

as for coded solution to just timerjob though .cs only:

add this to define the int val we would want to check against:

     private int timecounter = 10;

add following to page load event to run every 60 seconds:

        Timer t = new Timer();
        t.Tick += new EventHandler<EventArgs>(t_Tick);
        t.Interval = 60000

then create the event when above is called:

    private void t_Tick(object sender, EventArgs e)
    {
          timecounter--;
          if (timecounter == 0)
          {
                //reload page, somthing on the lines of
                HttpContext.Current.Response.Redirect(SPContext.Current.Web.Url);
          }
    }

instead of reload the page, you can rebind the listview by calling .bind() again, you would need to change the code slightly but it would work well instead of reloading whole page.

or

you can use JQuery or JavaScript

Refreshing custom developed web part

and

http://mmman.itgroove.net/2011/05/adding-an-auto-refresh-content-editor-web-part/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.