SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

not sure if this is even possible. What I'm trying to do is create a visual web-part for SharePoint 2010 (using Visual Studio 2013) that will allow the user to add the web-part to a page then add data to a text box, the data is then saved with the web-parts variables.

What I've tried so far is adding a button to the page that when clicked will set the variable but this doesn't seem to work as the page refreshes, which resets the content in the text-boxes to the stored data before the code can override it.

Does anyone know if this is even possible? Any help on this would be greatly appreciated as I've hit a brick wall. Cheers.

share|improve this question

I am not exactly sure what you mean by "webpart variable". When you click a button that causes a postback(the pages refreshes), you maybe reset your value in the textbox. What you can do is to set your textbox value only if it is not a postback:

protected void Page_Load(object sender, EventArgs e)
  if (!IsPostBack)
      myTextBox.Text = GetTheValue();

If it isn't what the problem is, please let me know.

share|improve this answer
Thanks for the reply, sorry by webpart variable I was talking about the properties of the webpart ` [WebBrowsable(true), Category("Accordion Data"), Personalizable(PersonalizationScope.Shared), WebDisplayName("Section 1 Title")] public String Section01Title { get; set; } ` What I'm trying to do is when my button is clicked set the string 'Section01Title' to what is entered in a textbox. I've tried the way you mentioned (Section01Title = txtBox.Text) but unfortunately this didn't work. – William Feb 20 '13 at 10:09
sorry the code I pasted made that look like a really messy response – William Feb 20 '13 at 10:13

For anyone that is wanting it I managed to figure it out.

protected void Button1_Click(object sender, EventArgs e)
        Section01Title = txtTitle01.Text;
        Section01Content = txtContent01.Text;

I was missing the "this.SetPersonalizationDirty();" line after setting the Sharepoint properties. Apparently this tells the web-part to save back to Sharepoint (from what I understand)

share|improve this answer

Your Answer


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.