GridView Click Event Not Firing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ADN

    GridView Click Event Not Firing

    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....
    }
    }



  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: GridView Click Event Not Firing

    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....
    }
    }
    >
    >
    >
    >

    Comment

    Working...