creating plugin interface

Hi all,

I have a custom control i have created (basically for displaying data in a dataview.)

Now i want to catch an event when a cell is left (so i can error check the cell contents.)

however this would be different (potentially) for each page the control is used on.

would it be possible (and if so how would i do it please) to create a plugin interface for this control and then override (when needed) this event?

thanks in advance.

Matt.
flynnyAsked:
Who is Participating?
 
Todd GerbertConnect With a Mentor IT ConsultantCommented:
In your custom control, you would handle one of the GridView's events, like RowUpdating.  Add your own event to the custom control, like MyRowUpdating; then in the event handler for the GridView's RowUpdating event you would raise your control's MyRowUpdating event.

When the user control is used in a page, that web page can add a handler for your control's MyRowUpdating event.

<script runat="server">
    protected void WebUserControl11_MyRowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        label1.Text = String.Format("Row updated: {0}", e.RowIndex);
    }
</script>

<uc1:WebUserControl1 ID="WebUserControl11" runat="server" OnMyRowUpdating="WebUserControl11_MyRowUpdating" />
public partial class WebUserControl1 : System.Web.UI.UserControl
{
    public event GridViewUpdateEventHandler MyRowUpdating;

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        OnRowUpdating(e);
    }

    protected virtual void OnRowUpdating(GridViewUpdateEventArgs e)
    {
        if (MyRowUpdating != null)
            MyRowUpdating(this, e);
    }
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.