Add an ASCX control to the page

Last updated Monday, January 16, 2017 in Web Forms for Marketers for Developer
Keywords: Web forms

In the Web Forms for Marketers module, you can convert and export a form to an .ascx file and then add it to your website as an ASCX control. For developers, this can make it easier to develop their custom form control.

To add an ASCX control to the page:

  1. Using a text editor, in the \layouts folder of your Sitecore installation, create a new default.aspx page and insert the following code:
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body> 
        <form id="form1" runat="server">
        </form>
    </body>
    </html>
  2. In the Form Designer, in the Export group, click To ASCX and export the relevant form data to the \layouts folder. Use the forms.ascx format for the name of the file.
  3. In the default.aspx page that you created, add the following code after the first <%@ Page> tag:
     <%@ Register Src="form.ascx" TagName="SimpleForm" TagPrefix="uc1" %>
  4. Inside the <form> tag, insert the following code:
         <div>
            <uc1:SimpleForm ID="WebUserControl1" runat="server" />        
         </div>
        </form>
  5. In your web browser, enter the following URL: http://localhost/layouts/default.aspx.

Note

After you make changes to the .ascx file, the module does not verify that the form works correctly

Send feedback about the documentation to docsite@sitecore.net.