How to Convert HTML to Aspx


The best way to convert an HTML page to an ASPX page is to create the ASPX file and transfer the HTML text. ASPX files are specially coded pages that have specific syntax. Several distinguishable differences are in an ASPX page compared to HTML. Knowing these differences will help you convert an HTML page to an ASPX file.

  • Open Visual Studio and create a new web page in the works space. Creating a new web page in Visual Studio automatically adds some of the header code necessary for the compiler to run the page. For instance, in an ASPX file, the below code is the first line in every file:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="<codefilename.aspx.cs" Inherits="codefilename" %>

  • Copy HTML tags from the HTML page to the newly created ASPX page. The best way to copy tags is by copying the header tags first, then copying the tags within the body, then copy and Javascript code.

  • Insert "runat=server" in all tags that need to be used with the code-behind file. Using "runat=server" allows the ASPX compiler to use that tag in the code. For instance, if you need to use a text box in the ASPX code-behind to manipulate user input, the text box HTML tag needs "runat=server" inserted. Below is an example of an HTML tag with the "runat=server" inserted:
    <div runat="server" id="myDiv"></div>

  • Ensure tags with the "runat=server" inserted have an ID property assigned. Although this isn't necessary in HTML, an ASPX page needs ID properties assigned to use the elements in the code-behind file. Below is an example of a tag with an ID property:
    <div runat="server" id="myDiv">My Div</div>

  • Remove HTML form tags. When you create the ASPX page, you see a "form" tag automatically inserted. ASPX files have one form tag that envelopes all the code in the "body" tag. If you leave other "form" tags in the ASPX file, an error is returned.

  • Save the file and test it in the web browser. You can test an ASPX file using the internal Visual Studio browser. Right-click the page and select "Open in browser" to test the page.


Promoted By Zergnet


You May Also Like

Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!