Converting Web Pages to User Controls in .NETThere are instances where you would like to use web page functionality repeatedly within your application and you might want to convert it to a user control so that you can do so. It is easy to convert a web page to a user control with some minor modifications in it. As you know the user control files have an extension .ascx, you have to change the file extension of the web page to that of .ascx. For this you can use the Rename functionality found in the context menu from the Solution Explorer. After renaming the file, you have to remove the html, body, and the form tags found in the web page. Now coming to the top of the page, you will have the @page directive. Now change the @page directive to a @control directive. The attribute like language, AutoEventWireup, CodeFile and Inherits can be left as it is. Add an attribute called className to the @control directive and give a ClassName. Now you are ready to use this user control in the web page of your choice.
|