0

I got the following event code wich is called when clicking a button:

void addSubject_Click(object sender, EventArgs e)
{
 SPWeb thisWeb = SPContext.Current.Web;
 thisWeb.AllowUnsafeUpdates = true;

 SPList productList = thisWeb.List["Documents"];
 SPview view = productList.Views["All Items"];

 view.ViewFields.Add("Subject");

 view.Update();
 productList.Update();
}

On my sitepage, where I inserted the "Documents" web part, nothing happens. However if I click on the "Documents" link to the left to only see the "Documents" list, I can see the view has changed. Also if I choose "Edit web part" and change "Selected View" I can see the changes...So how do I see the changes directly when clicking the button??

Thanks

2 Answers 2

1

Redirect to the same page again, its not refreshing the View on the page!

EDIT:

System.Web.HttpContext.Current.Response.Redirect(System.Web.HttpContext.Current.Request.Url.ToString());
4
  • Alright..Sorry for being stupid but how exactly do I do that with code?
    – Jukke
    Commented Sep 30, 2013 at 13:35
  • @Jukke, see edited part Commented Sep 30, 2013 at 13:37
  • Thanks for trying, but I get an error: "the name 'response' does not exist in the current context"
    – Jukke
    Commented Sep 30, 2013 at 13:48
  • @Jukke see new update! Commented Sep 30, 2013 at 13:52
0

The View changes will not be displayed in the Documents WebPart. This is a standard SharePoint behavior. The given link has more information: How exactly do SharePoint 2010 List Views behave?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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