473,797 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(EventArg s e)
{
btnMyButton = new Button();
btnMyButton.ID = "btnMyButto n";
btnMyButton.Tex t = "Click Here";
btnMyButton.Ena bleViewState = true;
btnMyButton.Cli ck += new
System.EventHan dler(MyGridView _MyButtonClick) ;
base.OnInit(e);
}
protected override void Render(HtmlText Writer __writer)
{
btnMyButton.Ren derControl(__wr iter);
base.Render(__w riter);
}
public void MyGridView_MyBu ttonClick(objec t sender, EventArgs
e)
{
//=== Button Click Event code goes here....
}
}

Jun 27 '08 #1
1 2870
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 createchildcont rols.

-- 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(EventArg s e)
{
btnMyButton = new Button();
btnMyButton.ID = "btnMyButto n";
btnMyButton.Tex t = "Click Here";
btnMyButton.Ena bleViewState = true;
btnMyButton.Cli ck += new
System.EventHan dler(MyGridView _MyButtonClick) ;
base.OnInit(e);
}
protected override void Render(HtmlText Writer __writer)
{
btnMyButton.Ren derControl(__wr iter);
base.Render(__w riter);
}
public void MyGridView_MyBu ttonClick(objec t 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
1038
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 ((Label)GridView1.Rows.Cells.FindControl("Label5")).Text = e.Node.Text;
28
10280
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 appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
3
8852
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 one call to my handler? I'm using the most basic wiring as it comes out of VS 2005.. Thanks in advance for your help! ex/ <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
4
6734
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 event in GridView? I thought it would be RowCommand, but I can't get that event to fire with a check box field that I drag/drop in a template column in the ItemTemplate. 2.) For a Templated column, like a check box above, where do I tell it the...
6
28177
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 RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
1
2250
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 button click event fires, no problem. But the event for the EditCommand does not fire. Any Ideas? Any one else seen this? Here is some code: <cc2:ScriptManager ID="atlasScriptManager" runat="server"
9
26928
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 error message. I put a breakpoint on the RowUpdating event handler and found that the event is not fired. Right now, I have not written code for the Update event. I am just wondering why the event is not firing. Here Person_ID is the primary key....
0
2904
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 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...
11
6070
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 if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.