Modularizing is always a good idea to simplify code. With the Extract to User Control feature, we have a powerful tool that will help us with this refactoring functionality.
Getting ready
In order to use this recipe you should have Visual Studio 2012.
How to do it...
Here we are going to show how to easily generate a user control from a section of code in our web page.
Open our previous ASP.NET application or create a new one.
If you created a new application, add a control and customize it to your liking.
Open the Site.Master page.
Go to the div body and select the <section> element surrounding it.
Right-click on the selected code and click on the Extract to User Control option.
On theSave as dialog, assign the name ListOfCategories.ascx and click on the OK button.
Now we will need to move the GetBookCategories() method from the code, as the related methods are not moved.
How it works...
We simply created a user control based on a section of our HTML code. We just have to remember to move the methods and code that are not moved.