making a placeholder show multiple lines...

Posted on 2007-08-08
Last Modified: 2013-11-05

I hjave this code that i'm using to show a link on a site - but i want to be able to show multiple there anyway to do this with a placeholder?

so when i click the button it shows me the link - when i click it again - it clears the first link and put a new one - i want it to show the old one and the new one...

HyperLink hl;
             hl = new HyperLink();
             hl.Target = "blank";
             hl.Text = link;
             hl.NavigateUrl = link;
Question by:mrperfect75000
    1 Comment
    LVL 21

    Accepted Solution

    that happens because each time you press a button your page is sent back to the server and then re-rendered anew - affectively resetting anything what you did before the button was pressed (adding hyper links in your case) - that's basic mechanic of web pages.

    if you create any dynamic controls, you have to create 'em each time your page is loaded. you can do it in several methods, but for now we'll stick with page load. you also will need to store your info between posts and we'll do it in the session control. Here is the sample web applications, you can copy-paste it into any new web app, see how it works, and use it in your own application. There're two parts, an aspx and a source code:

    ==== aspx ==============
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Place Holder.aspx.cs" Inherits="Place_Holder" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="" >
    <head runat="server">
        <title>Untitled Page</title>
        <form id="form1" runat="server">
                <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                <br />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />&nbsp;</div>

    ====== source code ================
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    public partial class Place_Holder : System.Web.UI.Page
          // collection of your hyper links
          Collection<HyperLink> hlinks = new Collection<HyperLink>();

          protected void Page_Load( object sender, EventArgs e )
                // on each page load we check if there is anything in the session for our links
                // and load all previously stored links in the place holder

                if( Session[ "links" ] != null )
                      hlinks = ( Collection<HyperLink> )Session[ "links" ];
                      foreach( HyperLink hlink in hlinks )
                            PlaceHolder1.Controls.Add( hlink );

          protected void Button1_Click( object sender, EventArgs e )
                // create a new link
                HyperLink hl = new HyperLink();
                hl.NavigateUrl = @"";
                hl.Text = "google " + DateTime.Now.ToLongTimeString();
                // add it to the holder for now
                PlaceHolder1.Controls.Add( hl );

                // and add it to the collection for after-post back
                hlinks.Add( hl );
                Session[ "links" ] = hlinks;

    You can add some literal controls after each hyperlink to break 'em to new lines as well.

    Good luck,


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now