Visual Studio 2012 Features – Extract To User Control

Ambily.Raj
Posted by in Visual Studio category on for Beginner level | Points: 250 | Views : 36149 red flag

Visual Studio 2012 introduces another great feature for creating a user control out of the existing code. Till now we used to create different User controls and use it in main page. Now, with the introduction of Visual Studio 2012, we are developing the pages and generate the User controls from the existing page design.

For our sample, I used the default ASP.Net web application created by the Visual Studio. The Default.aspx page looks like the below. 

 

 
Let us create our new User Control from the ordered list specified in the Default.aspx. Select the Code Snippet and right click to open the Context Menu.    



From the Context Menu, select “Extract to User Control” option. This will open the “Save as” window, where we need to specify the User Control name and select OK.

 

Now, Visual Studio will create the new “MyUserControl” user control and modify the Default.aspx page to utilize the same.   

MyUserControl is generated using the selected ordered list code as shown below.


Notice the changes in the Default.aspx page. Register tag for registering the user control is added on top of the page. Selected code snippet [in our case ordered list code] is replaced by the user control declaration.


 
Note: Visual Studio will copy only the designer code; it won’t copy the corresponding code behind code like the event handlers associated with the code snippet. 

Conclusion

Visual Studio 2012 introduced many new features to help developers to improve their productivity. New “Extract to user Control” feature help the developer to create a user control out of an existing code snippet.

Page copy protected against web site content infringement by Copyscape

About the Author

Ambily.Raj
Full Name: Ambily KK
Member Level: Silver
Member Status: Member,Microsoft_MVP,MVP
Member Since: 5/18/2010 1:05:25 AM
Country: India
Thanks Ambily K K http://ambilykk.com/
http://ambilykk.com/
I have over 9 years of experience working on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Office Open XML, Azure, Visual Studio 2010. Technology adoption and learning is my key strength and technology sharing is my passion.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)