Article posted by Ambily.Raj
on 9/4/2012 | Views: 3417 | Category: Visual Studio 2010/12
| Level: Beginner | Points: 250
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.
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.
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.
Found interesting? Add this to: