1. Download template for Visual Stuido 2010
Template can be download here, the template includes all the necessary references to Umbraco DLLs
2. Create new Web Application
By clicking “File > New Project > Visual C# > Umbraco UserControl”, make sure project name have no spaces, dots might also get you in trouble.
3. Create UserControl
.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EyeCatchCSVGenerator.ascx.cs" Inherits="EyeCatchCSVGenerator.EyeCatchCSVGenerator" %>
<h4>If everything works, the source node should show up below</h4>
<table id="sourcenode" runat="server"></table>
.cs
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.HtmlControls;
7: using System.Web.UI.WebControls;
8: using umbraco.presentation.nodeFactory;
9:
10: namespace EyeCatchCSVGenerator
11: {
12: public partial class EyeCatchCSVGenerator : System.Web.UI.UserControl
13: {
14: public int Source { get; set; }
15:
16: protected void Page_Load(object sender, EventArgs e)
17: {
18:
19: Node source = new Node(Source);
20:
21: HtmlTableRow r = new HtmlTableRow();
22: HtmlTableCell c1 = new HtmlTableCell();
23: HtmlTableCell c2 = new HtmlTableCell();
24: c1.InnerHtml = "Name: " + source.Name;
25: c2.InnerHtml = "ID:" + source.Id;
26:
27: r.Cells.Add(c1);
28: r.Cells.Add(c2);
29: sourcenode.Rows.Add(r);
30: }
31: }
32: }
4.Build your project and copy files to Umbraco install folder
copy .ascx file to \usercontrols
copy .dll file to \bin
5. Create macro
Choose .ascx file, click “Browse properties” and “Save properties”
6. Update template
<%@ Master Language="C#" MasterPageFile="/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>EyeCatch CSV Generator Demo Page</title>
</head>
<body>
<!-- Insert Macro Here! -->
</body>
</html>
</asp:Content>
Advertisement