Cancel execution of event handler?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I stop an event handler from executing? For example, I my Gridview
RowEditing event handler looks like this:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
int I = 0;
}

How can I stop execution of GridView1_RowEditing(...) so that the only thing
that runs when GridView1_RowEditing is invoked is the simple instruction with
the int?

Thanks.
 
Hi,
As Peter Broomberg has rightly said you need to handle e's cancel property.
For your reference i am writing below a sample code:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// For this example, cancel the edit operation if the user attempts
// to edit the record of a customer from the Unites States.
if (country == "USA")
{
// Cancel the edit operation.
e.Cancel = true;
Message.Text = "You cannot edit this record.";
}
else
{
Message.Text = "";
}

}

Thanks and Regards,
Manish Bafna.
MCP and MCTS.
 
Back
Top