user5038976
user5038976

Reputation:

Adding Hyperlinks dynamically

I want a page where hyperlinks are added o the page dynamically. Here is my code

<div class="md-content" id="divPopup"  runat="server">
    <div class="modal-header">
        <asp:Button ID="btnClose" runat="server" Text="Close" />    
    </div>    

    <div class="modal-body">
        <div class="label_wrap_docu">
            <asp:Label runat="server">Link Title</asp:Label></div>    
        <div class="text_feild_wrap_docu">
            <asp:TextBox runat="server" ID="txtTitle"></asp:TextBox></div>
        <div class="label_wrap_docu">
            <asp:Label runat="server">Link URL</asp:Label></div>    
        <div class="text_feild_wrap_docu">
            <asp:TextBox runat="server" ID="txtUrl"></asp:TextBox></div>
    </div>    
    <div class="modal-footer">    
        <asp:Button runat="server" ID="btnSubmit" Text="SUBMIT" OnClick="btnSubmit_Click" />
    </div>


protected void btnSubmit_Click(object sender, EventArgs e)
        {               
               HyperLink hyp = new HyperLink();
                hyp.Text = txtTitle.Text;
                hyp.NavigateUrl = txtTitle.Text;
                Page.Controls.Add(hyp);                    
        }

It is working.But one problem is that the old item is replaced by new item. It does not form a list. Can anyone please help me?

Upvotes: 1

Views: 2560

Answers (2)

Dot_NET Pro
Dot_NET Pro

Reputation: 2123

you can add like this:

<asp:BulletedList ID="BulletedList6" runat="Server" DisplayMode="HyperLink">

ListItem li = new ListItem();
li.Text="dynamichyperlink";
li.Value="www.google.com"
BulletedList6.Items.Add(li);

Upvotes: 1

Teun
Teun

Reputation: 175

You can create a Panel in your page, then in code add HyperLink instances to it's controls.

<asp:Panel ID="panel" runat="server"></asp:Panel>
// C#
HyperLink hyperLink = new HyperLink();
// Fill in your hyperlink details
panel.Controls.Add(hyperlink);

Upvotes: 0

Related Questions