Custom GridView with Button - Click Event Not Firing

Custom GridView with Button - Click Event Not Firing

Post by ADN » Wed, 23 Apr 2008 22:32:27


I am currently extending the GridView control and would like to add a
button to the GridView so that it will automatically render one button
at the top of the grid. I have a click event for that button, but
everytime the button is clicked, the page posts back and the click
event does not fire (probably because the button gets created every
single time there's a postback). What is the best way for me to create
this button and then make the click event fire?

I would like it so that I can drag my custom GridView onto an .aspx
page and not have to worry about handling any events on that page so
that it is all handled by my gridview. Is that even possible?

public class MyGridView : GridView
Button btnMyButton;

protected override void OnInit(EventArgs e)
btnMyButton = new Button();
btnMyButton.ID = "btnMyButton";
btnMyButton.Text = "Click Here";
btnMyButton.EnableViewState = true;
btnMyButton.Click += new

protected override void Render(HtmlTextWriter __writer)

public void MyGridView_MyButtonClick(object sender, EventArgs
//=== Button Click Event code goes here....

1. Custom toolbar button click events are not firing with infopath 2007

2. How could fire both TextChanged event and button click if button is clicked

I am using ASP.NET. I have 3 web server controls on my page. One is
textbox1 with AUTOPOSTBACK = true. The other one is another textbox2
with AUTOPOSTBACK = false. The third item is a save button.

Now, I want whenever textbox1 changes, system automatically fills in
value in textbox2. If user click on button, then system SAVE
information into database.

Now my problem is if when user change text in textbox1, instead of move
cursor ro anywhere else, he click on SAVE button. So the system will
fire page autopostback and fill in value in textbox2 but will not SAVE
this information. I do want to save the information when user click on

I understand that there is one one action server could response to
this. Is there anyway I could detect that user click on button instead
of moving cursor out of textbox1 area?

Thanks in advanced,

3. When user press F5 after a button click event, the click event fires again!

4. Add custom toolbar and double click on a button = event handler fired three times

5. Button Click events only firing on second click

6. Custom Control Click Event not firing.

7. Click event not firing with custom control

8. Image Button Click Event Does not fire

9. User Control Button Click event not firing when placed in a Web form

10. asp button click event does not fire

11. Button.Click not firing, but ONLY if I use the Textbox.Validating Event

12. ActiveX button's click event not being fired

13. Click ToolBar button does not fire Leave event of other control?

14. change of session does not fire button click event for second time

15. Click event of button added on word mail editor not firing