In my application, I have a lot of code for copying and pasting, which is exactly the same and performs exactly the same function (button click events, etc.). This redundant code lives in the code of many of my pages. Therefore, I decided to reduce duplication of code and transfer these methods to the class file and only call them from the code pages.
Here is an example of a button click event in my code for calling methods from a class file:
#region DELETE selected users - button
protected void btnDeleteSelected_Click(object sender, EventArgs e)
{
try
{
UserGvUtil.DeleteSelectedUsersAndProfiles(GridView1, Msg);
}
catch (Exception ex)
{
UserGvUtil.ExceptionErrorMessage(Msg, ex);
}
finally
{
UserGvUtil.RefreshGridView(GridView1);
}
}
#endregion
Is it possible to combine this try / catch block into another method and transfer it to the same class file? So the only thing I have in the click event is a single line of code.
Does it make sense to do this? Not sure why, but I would like my code behind the files to be as clean and simple as possible, so I can make all the changes in one place.
, . , .