Using the Extract to User Control feature

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.

  1. Open our previous ASP.NET application or create a new one.
  2. If you created a new application, add a control and customize it to your liking.
  3. Open the Site.Master page.
  4. Go to the div body and select the <section> element surrounding it.
  5. Right-click on the selected code and click on the Extract to User Control option.
    How to do it...
  6. On the Save as dialog, assign the name ListOfCategories.ascx and click on the OK button.
    How to do it...
  7. 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset