Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Hello I tried refresh Site from Adding Item, but if I try too Use SPUtility.Redirect("http://gzawistowskilap/SitePages/Event.aspx", SPRedirectFlags.Trusted, current); it's giving me a error which in this screen shot: enter image description here

I want to refresh all site of Sharepoint, not only the dialog box. Please help.

Here is all code of Adding Item method:

namespace Add4.EventReceiver1

{ /// /// List Item Events /// public class EventReceiver1 : SPItemEventReceiver { HttpContext current; public EventReceiver1() { current = HttpContext.Current; }

   /// <summary>
   /// An item is being added.
   /// </summary>
   public override void ItemAdding(SPItemEventProperties properties)
   {
       base.ItemAdding(properties);

       if (properties.List.Title == "Wpisy")
       {
           SPSite oSiteCollection = new SPSite("http://gzawistowskilap");
           SPWeb witryna = oSiteCollection.RootWeb;
           SPListItemCollection listaDniSwiatecznych = witryna.Lists["DR2013 Święta"].Items;
           SPList lstOtherList = properties.Web.Lists["Szczegoly"];

           // Stworzenie dwóch zmiennych typu data, jednej opisującej dzień Startowy, drugiej opisującej dzień końcowy
           DateTime dzienStart = new DateTime();
           DateTime dzienStop = new DateTime();

           // Podstawienie odpowiednich pól z propetisów pod wcześniej stworzone zmienne
           dzienStart = Convert.ToDateTime(properties.AfterProperties["DzienStart"]).ToUniversalTime();
           // Zaistniała też potrzeba odjęcia dwóch godzin
         // dzienStart = dzienStart.AddHours(-1.0);
           dzienStop = Convert.ToDateTime(properties.AfterProperties["DzienStop"]).ToUniversalTime();
         // dzienStop = dzienStop.AddHours(-1.0);
           // Uruchomienie pętli while, która to pętla będzie się wykonywać przez czas kiedy to zmienna dzienStart będzie mniejsza bądz równa zmiennej dzienStop


           while (dzienStart <= dzienStop)
           {
               foreach (SPListItem olistaDniSwiatecznych in listaDniSwiatecznych)
               {

                   if (dzienStart.ToShortDateString() == Convert.ToDateTime(olistaDniSwiatecznych["Data"]).ToShortDateString())
                   {
                       dzienStart = dzienStart.AddDays(1.0);
                       continue;
                   }
               }

                       // Sprawdzenie Ifem, czy wybrane dni są równe sobocie, lub niedzieli
                       if (dzienStart.DayOfWeek.ToString() == "Saturday" || dzienStart.DayOfWeek.ToString() == "Sunday")
                       {
                           // Jeżeli zmienna ciągle inkrementowana dzienStart jest równa sobocie, lub niedzieli, to wwtedy następuje powiększenie dnia o jeden, zaś potem następuje kontynuacja pętli
                           dzienStart = dzienStart.AddDays(1.0);
                           continue;
                       }
                       // W przeciwnym wypadku następuje dodanie obiektu do listy
                       else
                       {
                           SPListItem item = lstOtherList.Items.Add();
                           item["Kontrakt"] = properties.AfterProperties["Kontrakt1"];
                           item["Pracownik"] = properties.AfterProperties["Pracownik1"];
                           item["Dzien"] = dzienStart;
                           item["Procenty"] = properties.AfterProperties["Procenty"];
                           // item["ID z Czas Pracy Wpisy"] = properties.BeforeProperties["ID"];
                           dzienStart = dzienStart.AddDays(1.0);
                           item.Update();
                       }




           }

           SPUtility.Redirect("http://gzawistowskilap/SitePages/Event.aspx", SPRedirectFlags.Trusted, current);

       } 

   }
   // Koniec ItemAdding
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Where are you calling that method? If you're trying to get the page behind the modal to refresh, you'll need to run that code on the actual page that launched the modal - otherwise you're just going to redirect the iframe that holds all of the modal's content.

EDIT:

Okay, so based on your code, you're running this code within the event receiver, which appears to work. The problem is that you're trying to redirect to the page within the modal, which throws an error - seems like Wiki pages aren't great at this.

I think this StackOverflow answer will help: http://stackoverflow.com/questions/5278864/sharepoint-redirect-from-modal-window-to-non-modal-one

Basically, you can make a new page that writes out JavaScript to redirect the 'parent' page - something like (copied from linked SO post):

String script = String.Format("window.frameElement.navigateParent('{0}');",   SPHttpUtility.EcmaScriptStringLiteralEncode(urlToOtherPage));
page.ClientScript.RegisterStartupScript(page.GetType(), "redirectToPage", script, true);

Then, your redirect code can redirect to this page (add ?IsDlg=1 to the end to try and avoid modal issues as with wiki pages, I'd say)

Edit #2: Here's some more detailed steps... haven't had time to test this out, but as long as the redirect works you should be set.

  1. Use Visual Studio to create a new page, 'CloseModal.aspx' or something similar, that will deploy to your site.
  2. Within the code-behind of this page, add the following code:

    String urlToOtherPage = ""; String script = String.Format("window.frameElement.navigateParent('{0}');", SPHttpUtility.EcmaScriptStringLiteralEncode(urlToOtherPage)); page.ClientScript.RegisterStartupScript(page.GetType(), "redirectToPage", script, true);

  3. Within your event receiver, change your redirect code to this: SPUtility.Redirect("http://gzawistowskilap/SitePages/CloseModal.aspx?IsDlg=1",etc...)

Now, when the receiver executes, it should redirect the modal to CloseModal.aspx, which will run JS that will redirect the client. I tested the JS snippet out and that works when run within a modal window.

share|improve this answer
    
I calling that method from Adding Item method I will put all code to the question. –  Grzegorz Z Nov 4 '12 at 8:01
    
I upgraded question –  Grzegorz Z Nov 4 '12 at 8:06
    
Got it - see updates to my answer. –  Ted N. Nov 4 '12 at 8:17
    
But it isn't see page in the context. –  Grzegorz Z Nov 4 '12 at 8:35
1  
Yeah, all you can do within the event receiver, with the httpcontext, is redirect the modal to a brand new page - then in the initialization of that page, you can execute the code I pasted in, which will use JavaScript to redirect the client. –  Ted N. Nov 4 '12 at 19:16
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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