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

  • Home
  • SEARCH
  • 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 6695937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:16:55+00:00 2026-05-26T06:16:55+00:00

In my sharepoint web-part application. I am dynamically generating LinkButtons as below. and this

  • 0

In my sharepoint web-part application. I am dynamically generating LinkButtons as below. and this works fine

foreach (var pName in productTypesNames[productType] )
{
   var subLi = new HtmlGenericControl("li");
   var linkButton = new LinkButton{ Text = pName };
   linkButton.Click += new EventHandler(linkButton_Click);
   subLi.Controls.Add(linkButton);
   ul.Controls.Add(subLi);
}

However, when I click on one of the links in UI, my debugger never hits the breakpoint that is set at very first line of

void linkButton_Click(object sender, EventArgs e)
{
}

More Code

protected void StateClicked(object sender, CommandEventArgs e)
{
  //Generate a dictionary of type Dictionary<string, List<string>>
  //Display the dictionary
  foreach (var productType in productTypesNames.Keys)
        {
            var li = new HtmlGenericControl("li");
            nav.Controls.Add(li);
            var ul = new HtmlGenericControl("ul");

            var anchor = new HtmlGenericControl("a");
            anchor.Attributes.Add("href", "#");

            foreach (var pName in productTypesNames[productType] )
            {
                var subLi = new HtmlGenericControl("li");
                var linkButton = new LinkButton{ Text = pName };
                linkButton.Click += new EventHandler(linkButton_Click);
                subLi.Controls.Add(linkButton);
                ul.Controls.Add(subLi);
            }
            anchor.InnerHtml = productType;
            li.Controls.Add(anchor);
            li.Controls.Add(ul);
        }
 }

Where stateClicked is called by a click on the image map of USA.

  • 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-26T06:16:56+00:00Added an answer on May 26, 2026 at 6:16 am

    You probably aren’t recreating the dynamically generated links on every postback.

    If you have a if (!IsPostback) wrapped around your foreach, try removing it.

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

Sidebar

Related Questions

I have created a SharePoint web part and inside this web part I am
In sharepoint my web part is calling a web service. This web service does
I created a simple Sharepoint web part which hosts a silverlight application. I created
I have a custom sharepoint web part that is throwing the following exception: System.Security.SecurityException:
I am creating a SharePoint web part in C# and part of it outputs
I'm trying to create a SharePoint web part that will display all the users
My Sharepoint 2007 web part executes code to start a K2 workflow process. The
What is best practice, in sharepoint 2007 web part deployment. Deploying the dll's to
I've built a web part for Sharepoint that retrieves data from an external service.
I wrote a custom web part for SharePoint 2007 that loads an existing user

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.