Tutorial :combining methods



Question:

In my app I have a lot of copy and paste code that is exactly the same and performs exactly the same function (button click events and the like). These redundant code live in the code-behind of many of my pages. So I decided to reduce the code duplication and to move these methods into a class file and only make a call to them from the code-behind pages.

Here is an example of a button click event in my code behind calling the 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);      }  }    





        
Previous
Next Post »