Guillaume Martin
Guillaume Martin

Reputation: 103

How to override custom Control Event?

I made a custom gridView class which inherits from GridView.

public class CustomGridView : GridView {}

It adds a textbox in the footerRow, and I'd like to manage the changed event for this textbox directly in my page, and not in the class.

Something like :

public override void txtSearch_TextChanged(object sender, EventArgs e) { }

How could I do this ?

Upvotes: 0

Views: 4514

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

You would have to add a new event to your CustomGridView and raise that in the handler of the TextChanged event of the textbox.

So, in your CustomGridView:

public event EventHandler FooterTextChanged;

private void RaiseFooterTextChanged()
{
    var handler = FooterTextChanged;
    if(handler == null)
        return;

    handler(this, EventArgs.Empty);
}

public override void txtSearch_TextChanged(object sender, EventArgs e)
{
    RaiseFooterTextChanged();
}

In the class that uses CustomGridView:

customGridView.FooterTextChanged += OnGridFooterTextChanged;

Upvotes: 2

Related Questions