Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:21:48+00:00 2026-06-17T09:21:48+00:00

Hi Stackoverflow community! I’m working on a Sharepoint 2013 Server with Visual Studio 2012

  • 0

Hi Stackoverflow community!
I’m working on a Sharepoint 2013 Server with Visual Studio 2012 and Windows Server 2012. So, I have to build a Webpart which should add a link via textbox to the GUI. Furthermore, it should be possible to add another link as well. After adding a new link, the whole collection of links should be displayed in a list. The problem is now: after adding a link, the site reloads. As a consequence the array, which stores the links, does only contain the latest link. All previous links are gone/deleted.

Here’s my approach on this:

    protected void Page_Load(object sender, EventArgs e) {
        if (Page.IsPostBack) {
            Events = new List<String>();
        }
    }

    protected void btnAddLink_click(object sender, EventArgs e) {
        AddToList();
        List<String> links = Events;
        foreach (String s in links) {
            HyperLink link = new HyperLink();
            link.NavigateUrl = s;
            link.Text = s;
            lnkPanel.Controls.Add(link);
        }
        foreach (String l in links) {
            tbDescription.Text += l + "\n";
        } 
    }

    public List<String> Events {
        get { return (List<String>)ViewState["HyperLinkList"]; }
        set { ViewState["HyperLinkList"] = value; }
    }

    public void AddToList() {
        List<String> events = Events; // Get it out of the viewstate
        String l = tbLinks.Text; // tb = textbox (user input)
        HyperLink link = new HyperLink();
        link.NavigateUrl = tbLinks.Text;
        link.Text = tbLinks.Text;
        if (!events.Contains(link.NavigateUrl.ToString())) {
            events.Add(l);
        }
        Events = events; // Add the updated list back into the viewstate

    }

I hope someone can help me with my (maybe nooby) problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:21:48+00:00Added an answer on June 17, 2026 at 9:21 am

    Ahhh you need this:

    protected void Page_Load(object sender, EventArgs e) {
        if (!Page.IsPostBack) {
            Events = new List<String>();
        }
    }
    

    Each time the page is loaded, your wiping the contents of the list in viewstate. You need to add the ! to make sure it’s not a postback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello StackOverflow Community, I have this JUnit Tests that need to run a Server
Hi StackOverflow community, in my application I'd like to have a button which allows
Hello again, stackoverflow community! I'm working on writing a simple blog system in Rails,
Hello StackOverflow community, Is there any way to open a folder in Windows Explorer
Hello StackOverflow community, I have run into a problem that quite frankly is baffling
Hey StackOverflow community, My question is as follows: I have a table, say USER_ADDR
Hello stackoverflow community, I have a rather simple piece of code that is getting
I have a decision to make and I'm kicking it to the stackoverflow community.
Hello, stackoverflow community! I am working on a rather large database-driven web application. The
Hi Stackoverflow community, I am working on some code where a list of optional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.