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. Problem with an event being handled

Problem with an event being handled

Scheduled Pinned Locked Moved ASP.NET
helpcsharphtmlasp-netquestion
2 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.
  • O Offline
    O Offline
    Omega501
    wrote on last edited by
    #1

    I'm just learning asp.net and am trying to create a page that asks how many items I want displayed, then it displays the items followed by a submit button. This button has a click event assigned to it, but for some reasone the button never fires - the page just submits and reloads the original page. The first button is created in html on the page, but the second button is created only in code. button1 click handler

    private void Button1_Click(object sender, System.EventArgs e) {
    int intNumQ = int.Parse(TextBox1.Text);
    Panel1.Controls.Clear();
    Table QContainer = new Table();
    TableRow QRow;
    TableCell QCell;
    Panel1.Controls.Add(QContainer);
    for(int i = 0; i< intNumQ; i++){
    // add items list
    }
    // create button 2
    btn = new Button();
    this.btn.Click += new System.EventHandler(btn_Click);
    btn.Text = "Click me too";
    btn.ID = "getvalues";
    Panel1.Controls.Add(btn);
    }

    Button 2 is created on the page, but for some reason the click event doesn't get hendled - any idea on what i'm doing wrong? button 2 click handler

    private void btn_Click(object sender, System.EventArgs e){
    Literal output = new Literal();
    // get values and output to the page
    Panel1.Controls.Add(output);
    }

    I've been looking through this forum and others for a solution, but from what I've seen I'm not doing anything wrong. This has been driving me :confused: for the last few days so any help would be much appreciated

    P 1 Reply Last reply
    0
    • O Omega501

      I'm just learning asp.net and am trying to create a page that asks how many items I want displayed, then it displays the items followed by a submit button. This button has a click event assigned to it, but for some reasone the button never fires - the page just submits and reloads the original page. The first button is created in html on the page, but the second button is created only in code. button1 click handler

      private void Button1_Click(object sender, System.EventArgs e) {
      int intNumQ = int.Parse(TextBox1.Text);
      Panel1.Controls.Clear();
      Table QContainer = new Table();
      TableRow QRow;
      TableCell QCell;
      Panel1.Controls.Add(QContainer);
      for(int i = 0; i< intNumQ; i++){
      // add items list
      }
      // create button 2
      btn = new Button();
      this.btn.Click += new System.EventHandler(btn_Click);
      btn.Text = "Click me too";
      btn.ID = "getvalues";
      Panel1.Controls.Add(btn);
      }

      Button 2 is created on the page, but for some reason the click event doesn't get hendled - any idea on what i'm doing wrong? button 2 click handler

      private void btn_Click(object sender, System.EventArgs e){
      Literal output = new Literal();
      // get values and output to the page
      Panel1.Controls.Add(output);
      }

      I've been looking through this forum and others for a solution, but from what I've seen I'm not doing anything wrong. This has been driving me :confused: for the last few days so any help would be much appreciated

      P Offline
      P Offline
      Pradhip
      wrote on last edited by
      #2

      In VB WE GENERALLY HANDLE EVENTS LIKE private sub btn_Click(object as sender, e as System.Eventargs) handles Btn_click.cliked --- --- --- ---- end sub the handles key word is impt and denotes what the event handles.This is using the codebehind page model.So there must be some equivalent in c#.Look out for that piece of info. Hope this helps. Pradhip.S If a Building is Completed then why do they call it BUILDING ??

      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