Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Button event does not execute

Button event does not execute

Scheduled Pinned Locked Moved ASP.NET
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    netJP12L
    wrote on last edited by
    #1

    Hi Guys, I am loading buttons on a page load event dynamically. The buttons are added to a placeholder control on a aspx page. The problem I am having is that the dynamically created button event below (topic_Click) doesn't get fired. Bascially, I am trying to add topics to aobjective. Could you please help me. I would highly appreciate it.

    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session\["s"\] == null)
        {
            AddObjective();
            AddTopic();
        }
        else if (Session\["s"\] != null)
        {
            List list = new List();
            list = Session\["s"\] as List;
            foreach (var item in list)
            {
                AddtoPlaceHolder(item);
            }
        }
    }
    

    private void AddObjective()
    {
    Panel panel = new Panel();
    Button objective = new Button();
    objective.Text = "Add objective";
    objective.Click += new EventHandler(objective_Click);
    panel.Controls.Add(objective);
    placeholder.Controls.Add(panel);

        AddtoPlaceHolder(panel);       
    }
    

    void AddtoPlaceHolder(Panel panel)
    {
    if (Session["s"] == null)
    {
    List list = new List();
    list.Add(panel);
    Session.Add("s", list);
    }
    else if(Session["s"] !=null)
    {
    List list = Session["s"] as List;
    list.Add(panel);
    Session.Add("s", list);
    }
    }

    void objective_Click(object sender, EventArgs e)
    {
    if (Session["s"] != null)
    {
    AddObjective();
    }
    }

    void topic_Click(object sender, EventArgs e)
    {
    throw new NotImplementedException(); =======> Problem doesn't execute
    }

    private void AddTopic()
    {
    Panel paneltopic = new Panel();
    paneltopic.ID = Guid.NewGuid().ToString();
    Button topic = new Button();
    topic.ID = Guid.NewGuid().ToString();
    topic.Text = "Insert topic";
    topic.Click += new EventHandler(topic_Click);
    paneltopic.Controls.Add(topic);
    placeholder.Controls.Add(paneltopic);

        AddtoPlaceHolder(paneltopic);
    

    }

    J 1 Reply Last reply
    0
    • N netJP12L

      Hi Guys, I am loading buttons on a page load event dynamically. The buttons are added to a placeholder control on a aspx page. The problem I am having is that the dynamically created button event below (topic_Click) doesn't get fired. Bascially, I am trying to add topics to aobjective. Could you please help me. I would highly appreciate it.

      protected void Page_Load(object sender, EventArgs e)
      {

          if (Session\["s"\] == null)
          {
              AddObjective();
              AddTopic();
          }
          else if (Session\["s"\] != null)
          {
              List list = new List();
              list = Session\["s"\] as List;
              foreach (var item in list)
              {
                  AddtoPlaceHolder(item);
              }
          }
      }
      

      private void AddObjective()
      {
      Panel panel = new Panel();
      Button objective = new Button();
      objective.Text = "Add objective";
      objective.Click += new EventHandler(objective_Click);
      panel.Controls.Add(objective);
      placeholder.Controls.Add(panel);

          AddtoPlaceHolder(panel);       
      }
      

      void AddtoPlaceHolder(Panel panel)
      {
      if (Session["s"] == null)
      {
      List list = new List();
      list.Add(panel);
      Session.Add("s", list);
      }
      else if(Session["s"] !=null)
      {
      List list = Session["s"] as List;
      list.Add(panel);
      Session.Add("s", list);
      }
      }

      void objective_Click(object sender, EventArgs e)
      {
      if (Session["s"] != null)
      {
      AddObjective();
      }
      }

      void topic_Click(object sender, EventArgs e)
      {
      throw new NotImplementedException(); =======> Problem doesn't execute
      }

      private void AddTopic()
      {
      Panel paneltopic = new Panel();
      paneltopic.ID = Guid.NewGuid().ToString();
      Button topic = new Button();
      topic.ID = Guid.NewGuid().ToString();
      topic.Text = "Insert topic";
      topic.Click += new EventHandler(topic_Click);
      paneltopic.Controls.Add(topic);
      placeholder.Controls.Add(paneltopic);

          AddtoPlaceHolder(paneltopic);
      

      }

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      protected void topic_Click(object sender, EventArgs e)
      {
      throw new NotImplementedException(); =======> Problem doesn't execute
      }

      private void AddTopic()
      {
      Panel paneltopic = new Panel();
      paneltopic.ID = Guid.NewGuid().ToString();
      Button topic = new Button();
      topic.ID = Guid.NewGuid().ToString();
      topic.Text = "Insert topic";
      topic.Click += new System.EventHandler(this.topic_Click);
      paneltopic.Controls.Add(topic);
      placeholder.Controls.Add(paneltopic);

          AddtoPlaceHolder(paneltopic);
      

      }

      [code behind event handlers^]

      A 1 Reply Last reply
      0
      • J jkirkerx

        protected void topic_Click(object sender, EventArgs e)
        {
        throw new NotImplementedException(); =======> Problem doesn't execute
        }

        private void AddTopic()
        {
        Panel paneltopic = new Panel();
        paneltopic.ID = Guid.NewGuid().ToString();
        Button topic = new Button();
        topic.ID = Guid.NewGuid().ToString();
        topic.Text = "Insert topic";
        topic.Click += new System.EventHandler(this.topic_Click);
        paneltopic.Controls.Add(topic);
        placeholder.Controls.Add(paneltopic);

            AddtoPlaceHolder(paneltopic);
        

        }

        [code behind event handlers^]

        A Offline
        A Offline
        archifux
        wrote on last edited by
        #3

        if you copy and past the code from another page visual studio may change the name of the button check the the ButtonID if its correct with the code

        J 1 Reply Last reply
        0
        • A archifux

          if you copy and past the code from another page visual studio may change the name of the button check the the ButtonID if its correct with the code

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          You should probably tell the OP that, and not me. The button ID has nothing to do with generating a postback to the server. In fact, you don't need the .ID attribute in code behind, it's there to support java script and css on the client side. His problem is that he didn't generate a new event object, and just made a reference to an uninitialized event object.

          A 1 Reply Last reply
          0
          • J jkirkerx

            You should probably tell the OP that, and not me. The button ID has nothing to do with generating a postback to the server. In fact, you don't need the .ID attribute in code behind, it's there to support java script and css on the client side. His problem is that he didn't generate a new event object, and just made a reference to an uninitialized event object.

            A Offline
            A Offline
            archifux
            wrote on last edited by
            #5

            I see here codebehind but what if on the design side button name is not "topic" what if the button name was "button1" thats what i am try to tell and its very possiable if you copy and past the design code

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups