473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

GridView Click Event Not Firing

ADN
Hi,

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
System.EventHandler(MyGridView_MyButtonClick);
base.OnInit(e);
}
protected override void Render(HtmlTextWriter __writer)
{
btnMyButton.RenderControl(__writer);
base.Render(__writer);
}
public void MyGridView_MyButtonClick(object sender, EventArgs
e)
{
//=== Button Click Event code goes here....
}
}

Jun 27 '08 #1
1 2817
you never add the button to the page control collection, so there is no way
for the event framework to find it, and tell it to fire the event. you should
add to the page control collection (or as a child of a control in the
collection) in the oninit or createchildcontrols.

-- bruce (sqlwork.com)
"ADN" wrote:
Hi,

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
System.EventHandler(MyGridView_MyButtonClick);
base.OnInit(e);
}
protected override void Render(HtmlTextWriter __writer)
{
btnMyButton.RenderControl(__writer);
base.Render(__writer);
}
public void MyGridView_MyButtonClick(object sender, EventArgs
e)
{
//=== Button Click Event code goes here....
}
}

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Shafia | last post by:
Hi, I have a TreeView and a GridView in my UI. On a "CheckChanged" event of tree, I do the following GridView1.Rows.Cells.Text = e.Node.Text; or rather ...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
3
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive...
4
by: Chris Davoli | last post by:
I've got two questions on how to do things in the new GridView. I'm used to the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview. 1.) What is the equavalent for Item Command...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
1
by: bill | last post by:
I have an update panel that contains a gridview. There are 2 triggers: one for a search button that is outside the panel and one for the gridview EditCommand Event. The search works fine, the...
9
by: John007 | last post by:
I am using a SQLDataSource to populate my gridview in ASP.Net 2.0. When I hit Edit, the textboxes appear and I am able to edit my values. When I hit Update, the changes are not saved, and there is no...
0
by: ADN | last post by:
Hi, 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...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.