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 6727437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:02:57+00:00 2026-05-26T10:02:57+00:00

plz see the aspx below first : <div id=divFilesBody> <div class=divFilesBody_Row> <%= Files %>

  • 0

plz see the aspx below first :

<div id="divFilesBody">
              <div class="divFilesBody_Row">
                <%= Files %>
                <a id="MyAnchor1" runat="server" OnServerClick="AnchorForDwonload_Click">Server Side Anchor 1</a>
            </div>

MyAnchor1 Serverside click event works perfect!
i want to make something like that from code behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using FileExplorer.Classes;

namespace FileExplorer.en
{
    public partial class Download : System.Web.UI.Page
    {
        public string Files = "";
        protected void Page_Load(object sender, EventArgs e)
        {
...
            foreach (FileInfo f in dir.GetFiles("*.*"))
            {
                Files += "<a class='MyAnchor2' runat='server' OnServerClick='AnchorForDwonload_Click'>";
                Files += "Server Side Anchor 2";
                Files += "</a>";
            }
        Files += "<a id='MyAnchor3' runat='server' OnServerClick='AnchorForDwonload_Click'>";
        Files += "Server Side Anchor 3";
        Files += "</a>";
        }

        protected void AnchorForDwonload_Click(object sender, EventArgs e)
        {
            Response.Write("Server Side Anchor Works");
        }

    }
}

but MyAnchor2 does not work after firing page load…
how can i solve this issue?

EDIT
i added MyAnchor3 After comment (An Anchor With ID) -> still does not work

the output html is like this :

        <a id='MyAnchor3' runat='server' OnServerClick='AnchorForDwonload_Click'>
        Server Side Anchor 3
       </a>

thanks in advance

  • 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-05-26T10:02:58+00:00Added an answer on May 26, 2026 at 10:02 am

    That is not the right way to create dynamic controls in ASP.NET. You can use LinkButton controls to achieve this:

    You should be doing something like this instead:

    Markup:

    <asp:Panel ID="pnlFilesBody" runat="server">
        <!-- resolves to a DIV -->
    </asp:Panel>
    

    Code-behind:

    protected override void OnInit(EventArgs e)  
    {   
        //create controls at every page load and assign the same ids to the controls
        //to preserve click events
    
        foreach (FileInfo f in dir.GetFiles("*.*"))  
        { 
            //create a new linkbutton
            LinkButton btn = new LinkButton();
            btn .ID = String.Format("lnk_{0}", pnlFilesBody.Controls.Count);
            btn.Click += new EventHandler(btn_Click);
            btn.Text = String.Format("Server Side Anchor {0}", pnlFilesBody.Controls.Count);
    
            //add the linkbutton to the files body panel
            pnlFilesBody.Controls.Add(btn);
        }
    }
    
    protected void btn_Click(object sender, EventArgs e)
    {
        //put your click event logic here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

plz see the below html : <head runat=server> <title></title> <style type=text/css> html, body {
plz see the below link : Long File Name Inside A Div when you
plz see the below codes : 1 2 3 +1+ $(document).ready(function() { //Do Some
plz see the below handler : using System; using System.Collections.Generic; using System.Linq; using System.Web;
plz look at the below codes : foreach (FileInfo f in dir.GetFiles(*.*)) { Files
I wanted to write following query through codeigniter's db helper class, guide me plz
plz see my global.asax : using System; using System.Collections.Generic; using System.Linq; using System.Web; using
First Image u can see List of college. When i clicked first college i
Hi Guys! It's the first time I see an image slider like status bar
plz guide me how I can enable or disable asp.net validation controls using jQuery

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.