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. how to fire event at run time

how to fire event at run time

Scheduled Pinned Locked Moved ASP.NET
helptutorial
4 Posts 2 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.
  • S Offline
    S Offline
    Sapan Roy
    wrote on last edited by
    #1

    Hi, all I have a Button is being created at run time. Like for(i=0;i<10;i++) { Button btn = new Button(); btn.id= "btn" + i; btn.click = new Handler(btn_click); panel1.controls.add(btn); } And the Event Handler is: ----------------------- protected void btn_click(sender, EventArgs ) { Response.write("Clicked"); } My problem is that handler is not fired. If I am putting the above code in Page_load then it is working. I there any way to come out. Please help me Thanks to all

    K 1 Reply Last reply
    0
    • S Sapan Roy

      Hi, all I have a Button is being created at run time. Like for(i=0;i<10;i++) { Button btn = new Button(); btn.id= "btn" + i; btn.click = new Handler(btn_click); panel1.controls.add(btn); } And the Event Handler is: ----------------------- protected void btn_click(sender, EventArgs ) { Response.write("Clicked"); } My problem is that handler is not fired. If I am putting the above code in Page_load then it is working. I there any way to come out. Please help me Thanks to all

      K Offline
      K Offline
      Kuricheti
      wrote on last edited by
      #2

      Hi sapan... Try this code

      Pgae Load..
      {
      Button btn = new Button();
      btn.ID = "btn" + i;
      btn.Click += new EventHandler(btn_Click);
      panel1.Controls.Add(btn);
      } //End Page Load
      protected void btn_Click(object sender, EventArgs e)
      {
      Response.Write("Clicked");
      }

      Regards Hari

      S 1 Reply Last reply
      0
      • K Kuricheti

        Hi sapan... Try this code

        Pgae Load..
        {
        Button btn = new Button();
        btn.ID = "btn" + i;
        btn.Click += new EventHandler(btn_Click);
        panel1.Controls.Add(btn);
        } //End Page Load
        protected void btn_Click(object sender, EventArgs e)
        {
        Response.Write("Clicked");
        }

        Regards Hari

        S Offline
        S Offline
        Sapan Roy
        wrote on last edited by
        #3

        hi hari, Actually that I know but my scenario is I have created many buttons on a particular event. Then later on when the buttons are generated. I have to click on that and event handlers should work according that. Actually in each post back page lost its contents is there any way to retain objects of page as well as event handlers associated with them. Thanks Sapan

        K 1 Reply Last reply
        0
        • S Sapan Roy

          hi hari, Actually that I know but my scenario is I have created many buttons on a particular event. Then later on when the buttons are generated. I have to click on that and event handlers should work according that. Actually in each post back page lost its contents is there any way to retain objects of page as well as event handlers associated with them. Thanks Sapan

          K Offline
          K Offline
          Kuricheti
          wrote on last edited by
          #4

          Hi Sapan You have to create dynamic controls every time during the page load... Thanks Hari

          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