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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:01:14+00:00 2026-05-30T11:01:14+00:00

I am writing a web app in asp.net. I have an aspx page that

  • 0

I am writing a web app in asp.net.
I have an aspx page that call a class (Test) that Generates a button and return the button.
The class constructor get the function that the button click event should activate (userClickOnButton)
and
insert to the button.click += EventHandler(“the name of the function (userClickOnButton)”);

the problem is that in the aspx behind code i use IsPostBack (cant take it off , need this Condition) and when i click on the button the progrem does not go to the event i created for the button, but when i take off the IsPostBack Condition the program does go to the event i created (the function userClickOnButton).

my code is:
aspx code behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Test test = new Test(userClickOnButton);
        Button button = test.AddButton();
        cell.Controls.Add(button);
    }
}

private void userClickOnButton(object sender, EventArgs e)
{
    this.ModalPopupExtenderSelectFilds.Show();
}

my class

public class Test
{

Action<object, EventArgs> m_ButtonClickActivateFunction;

public Test(Action<object, EventArgs> func) 
{
    m_ButtonClickActivateFunction = func;
}

public Button AddButton()
{
    Button button = new Button();
    button.Text = "select";
    button.ID = "buttonID";
    button.Click += new EventHandler(m_ButtonClickActivateFunction);

    return button;
}

need help to activate the event without taking out the IsPostBack Condition

thanks

  • 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-30T11:01:16+00:00Added an answer on May 30, 2026 at 11:01 am

    I think asp.net doesn’t handle clicks on buttons that no longer exist. Since on postback you don’t recreate the button and the button therefore does no longer exist in the controls collection of the page, the event is not handled.

    Handling of the event happens after Page_Load, so Page_Load should have recreated the button.

    Have a look here as well: Asp.Net Page Life Cycle

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

Sidebar

Related Questions

I am writing an web app in asp.net, In the code behind I have
I often find when I'm writing a service class (within an ASP.NET app) that
Background: I'm writing ASP.NET MVC 3 Web app. I have a List<MyObject> (actually several
I am being tasked with writing an asp.net web app that will use ADFS
I'm writing a project in c# asp.net mvc3, and I have a helper-class that
I am writing a web app in asp.net, in one of my aspx pages
I have an existing asp.net web app that uses facebook to authenticate users. I
i'm totally noob to asp.net mvc and currently i'm writing an web app which
I'm writing an asp.net web app. and i've hit a bit of a brick
I'm writing a simple web app in PHP that needs to have write access

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.