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.
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 the Save 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.