Note that there are some explanatory texts on larger screens.

plurals
  1. POLabels removed from this.Controls keep reappearing
    primarykey
    data
    text
    <p>I am a novice <code>C#</code> programmer, trying to create a simple <code>RSS/Atom</code> aggregator webpart for a <code>SharePoint</code> site (I can't use the ootb part as I don't have an Enterprise licence).</p> <p>I have 3 buttons: </p> <ol> <li>New Feed, which takes a <code>URI</code> from the user and attempts to construct a label displaying the feed and add it to <code>this.Controls;</code> </li> <li>Clear Feeds, which clears all the displayed feeds (removing them from <code>this.Controls</code>) </li> <li>Default Feeds, which takes an <code>ArrayList</code> of default <code>URIs</code> and converts them each into labels (also adding them to <code>this.Controls</code>).</li> </ol> <p>Clearing the feeds works fine, as does reverting to the defaults. However, after clearing all the feeds and trying to add a new feed, the defaults are added as well (and only one new feed can be added at a time, the new one overwriting the old). I suspect this is because I don't fully understand the add/remove controls function. Code follows below:</p> <pre><code> ArrayList viewedFeeds = new ArrayList(); ArrayList defaultFeeds = new ArrayList(); //Contains several default feeds, e.g. BBC news (http://feeds.bbci.co.uk/news/rss.xml) private void newFeed_Click(object sender, EventArgs e) { renderFeed(userText.Text); } private void clearFeeds_Click(object sender, EventArgs e) { clearAllFeeds(); } private void defaultFeeds_Click(object sender, EventArgs e) { clearAllFeeds(); initialiseFeedViewer(); } private void clearAllFeeds() { foreach (Label feed in viewedFeeds) { this.Controls.Remove(feed); } viewedFeeds.Clear(); } private void initialiseFeedViewer() { foreach (string uri in defaultFeeds) renderFeed(uri); } private void renderFeed(String uri) { try { Label feed = new Label(); // Create a Syndicated feed reader, parse the XML and add the relevant text to the label "feed" feed.BorderStyle = System.Web.UI.WebControls.BorderStyle.Double; viewedFeeds.Add(feed); this.Controls.Add(feed); } catch (Exception ex) { //Print an error message (e.g. If the URI does not link to a suitable feed } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload