BlogEngine.NET Architecture and source Code Analysis series PART10: Development Extensions (Medium)

Source: Internet
Author: User
Tags abstract blogengine

Widget Gadgets

In the last article I introduced to you the important part of the development of BlogEngine.NET--extension. In this article I will show you another extension of its features, that is widget gadgets, mainly the development of the Widget standards and working principles.

What is widget and why should I use widgets

Widget is actually a small tool with an interface, mainly used in desktop areas, such as: Yahoo!widget, as well as Vista from the sidebar and so on. In BlogEngine.NET it is the small partition on the left or right side of the page, such as category List,calendar,tag cloud, which actually exists in many blogging systems, We call it the widget in the blogengine.net.

Widgets can provide many of the functions of the blog system to the user a unified interface access interface. If there are some features that need to be added to the page, the first thing we think about is whether we can make it as a widget, because the widget has a unified development standard that can be easily achieved.

Widgetbase and Widgeteditbase

In BlogEngine.NET, as an interface widget we just need to inherit the Widgetbase class. Widgetbase directly inherits UserControl, rewriting render to generate a unified widget interface, and as to what is shown in the specific widget, it is done by the custom widget class itself, In Widgetbase, there is an abstract method Loadwidget to complete the initialization of the Widget object, iseditable to indicate whether the widget can be edited, and if it can be edited, the Edit button will be output when render. The widget must also provide an editing interface (inherited by Widgeteditbase). It is also important to note that getsettings in Widgetbase obtains the appropriate configuration information (that is, content information) and is stored in cache according to Widgetid from Datastore (described above). Cache in this part of the processing of datastore use a lot, I hope you pay attention.

If a widget can be edited, it also needs a class that implements Widgeteditbase, which essentially gives the user an interface to modify the widget configuration information (specific content). It provides an abstract save method for saving modified information to Datastore, and a saved event for external eavesdropping for expansion.

All implemented widgets must be placed in the Widgets directory and named after the widget name, If you're just browsing, we can add a widget.ascx, and if you need to modify it, you need to add a edit.ascx, as an example of the implementation of a TextBox (which allows you to set some descriptive information about the author):

In Widgets\ The textbox contains the Widget.ascx and edit.ascx two files (plus codebehind altogether four), obtains loadwidget information and adds to the widget content in Widget.ascx.cs datastore (the method of overriding the parent class).

1/**////<summary>
2///This method works as a substitute for Page_Load. For should
3///data binding etc. instead of Page_Load.
4///</summary>
5public override void Loadwidget ()
6{
7 StringDictionary settings = GetSettings ();
8 if (settings. ContainsKey ("content"))
9 {
LiteralControl Text = new LiteralControl (settings["content"));
One by one. Controls.Add (text);
12}
13}
14
15/**////<summary>
16///Gets the name. It must be exactly the same as the folder that contains the widget.
17///</summary>
18///<value></value>
19public Override String Name
009
' Get ' {return ' TextBox ';}
22}
23
24/**////<summary>
25///Gets wether or not the widget can be edited.
26///<remarks>
27///the way a widget can be editable are by adding a Edit.ascx file to the widget folder.
28///</remarks>
29///</summary>
30///<value></value>
31public override bool Iseditable
32{
A. {return true;}
34}
35

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.