Friday, January 29, 2010

Convert Web Page to ASP.net User Control

Some situation comes into picture where we want to change the web page to User control.

Steps to convert asp.net web page to user control.

  1. Rename to the file extenstion (.aspx) to  a .ascx extension.
  2. Remove html, head, body, form tags from the page. 
  3. Change the "@ Page" directive to a "@ Control" directive. 
  4. Remove all attributes of the "@ Control" directive, except  Language, AutoEventWireup, CodeFile, and Inherits.
  5. Need to change the Inherits to have your new UserControl code behind file's name.
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserControlFilename.ascx.cs"  Inherits="UserControlFileName" %>
  6. Close and re-open the file to make squiggles go away.
  7. Open the code behind file and change the class it inherits from to UserControl, and the class name to match your .ascx file.
    public partial class UserControlFileName : System.Web.UI.UserControl
Hope this helps for some body.

0 Comments:

blogger templates | Make Money Online