by Ron
13. augustus 2011 11:03
- Make a Web User Control in Visual Studio the way you always do. If you never made a user control, try to learn how to make one first before you continue.
- Go to the folder widgets and copy a folder. For this example we copy the Calendar folder.
- Rename te folder to something new. For example Calendar2

- In the widget.ascx.cs file, put the foldername here (it must be exactly written as the name of the folder ----> Calendar2):

- In the widget.ascx file, rename the Inerits part to Calendar2 and the namespace in the widget.ascx.cs file to namespace Widgets.Calendar2:


- Now try to load the new widget. The advantage is that you can see errors later on.

- After this step, you are almost there. Find #region Public Methods in widget.ascx.cs:
public override void LoadWidget()
{
//PLACE YOUR ASCX code (webuser control code, page load part) HERE.
}
- Copy and paste the classes in your code from your ascx (web control) file:

- Now your widget should work! Here the empty code to get started:
widget.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="widget.ascx.cs" Inherits="Widgets.Calendar2.Widget" %>
<%@ Import Namespace="BlogEngine.Core" %>
<div style="text-align: center">
////////////YOUR CODE HERE/////////////
</div>
widget.ascx.cs
using ////////////YOUR CODE HERE/////////////
using App_Code.Controls;
namespace Widgets.Calendar2
{
public partial class Widget : WidgetBase
{
#region Properties
public override bool IsEditable
{
get
{
return false;
}
}
public override string Name
{
get
{
return "////////////YOUR FOLDERNAME HERE/////////////";
}
}
#endregion
#region Public Methods
public override void LoadWidget()
{
////////////YOUR CODE HERE/////////////
}
#endregion
}
}