Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

GridView Click Event Not Firing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ADN - 22 Apr 2008 20:51 GMT
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....
       }
   }
bruce barker - 22 Apr 2008 22:25 GMT
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)

> Hi,
>
[quoted text clipped - 39 lines]
>         }
>     }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.