473,903 Members | 3,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom GridView with Button - Click Event Not Firing


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) ;

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
//=== Button Click Event code goes here....
Jun 27 '08 #1
0 2912

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

Similar topics

by: Juan Romero | last post by:
Hey guys, I am working on a web custom control that basically draws a table (ASP Table) with a few child controls in the cells. I have a command button inside one of these cells. The problem I am running into is that I cannot get the click event of this object handled. I have tried wiring the event with "AddHandler" among other things and that seems not to work neither.
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
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" %>
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...
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"
by: Daniel | last post by:
I've created a custom control including some Literal ( constructed with html markup) and an ImageButton firing event ( add a vote ). public event VoteCommandEventHandler VoteCommand; protected override void CreateChildControls() { LiteralControl ltrBeforeVote = new LiteralControl(buildMarkupBeforeVoteButton()); this.Controls.Add(ltrBeforeVote );
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...
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of the screen. I have been unable to find any way to disable this button in Access 2007 and subsequently I have been forced to find ways to detect and handle the situations after the Access Close button has been clicked. I have been largely...
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,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.