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