Interface
Database Table (x_config)
Design view:
Data:
Help
Because the configuration information is shared globally, we use a help classProgramThe lifecycle is loaded only once:
Namespace appbox {public class xconfighelper {# region Fields & constructor // <summary> // cache in memory /// </Summary> Private Static xconfigcollection configs = new xconfigcollection (); /// <summary> /// load all configuration items /// </Summary> static xconfighelper () {reloadcoll ();} /// <summary> /// Reload all configuration items /// </Summary> Public static void reloadcoll () {configs = new select (). from <xconfig> (). executeascollection <xconfigcollection> ();} # endregion # Region Methods /// <summary> // obtain the configuration information /// </Summary> /// <Param name = "key"> </param>/ // <returns> </returns> Public static string getvalue (string key) {foreach (xconfig config in configs) {If (config. configkey = Key) {return config. configvalue ;}} return string. empty ;} /// <summary> /// set the value /// </Summary> /// <Param name = "key"> </param> /// <Param name = "value"> </param> Public static void setvalue (string key, string Value) {foreach (xconfig config in configs) {If (config. configkey = Key) {config. configvalue = value ;}}/// <summary> // save all the changed configuration items /// </Summary> Public static void saveall () {configs. saveall ();} # endregion # region properties // <summary> // website title // </Summary> Public static String title {get {return getvalue ("title ");} set {setvalue ("title", value );}} /// <summary> /// number of entries displayed on each page in the list /// </Summary> Public static int pagesize {get {return convert. toint32 (getvalue ("pagesize");} set {setvalue ("pagesize", value. tostring () ;}/// <summary> // menu style (Accordion, tree menu) /// </Summary> Public static string menutype {get {return getvalue ("menutype");} set {setvalue ("menutype", value) ;}# endregion }}
aspx tag
<Ext: pagemanager id = "pagemanager1" autosizepanelid = "simpleform1" runat = "server"/> <Ext: simpleform id = "simpleform1" runat = "server" labelwidth = "100px" bodypadding = "5px" enablebackgroundcolor = "true" showborder = "false" Title = "system settings"> <items> <Ext: textbox id = "tbxtitle" runat = "server" label = "website title" required = "true" showredstar = "true"> </ext: textbox> <Ext: numberbox id = "nbxpagesize" runat = "server" label = "Number of table display items" required = "true" showredstar = "true"> </ext: numberbox> <Ext: dropdownlist id = "ddlmenutype" label = "menu style" runat = "server" required = "true" showredstar = "true"> <Ext: listitem text = "accordion" value = "accordion"/> <Ext: listitem text = "tree menu" value = "Tree"/> </ext: dropdownlist> <Ext: button id = "btnsave" runat = "server" validateforms = "simpleform1" text = "Save settings" onclick = "btnsave_onclick"> </ext: button> </items> </ext: simpleform>
There are some attributes to be aware:
- The pagemanager property autosizepanelid = "simpleform1", specifying that simpleform1 is full of the entire page
- The showborder = "false" attribute of simpleform1 removes the blue border (because this simpleform is embedded into another page in the form of IFRAME)
- The attribute enablebackgroundcolor = "true" of simpleform1 indicates the blue background color.
- Tbxtitle attributes required = "true" and showredstar = "true", specifying required and red tags
- The btnsave attribute validateforms = "simpleform1". Click this button to verify the form (multiple forms can be specified and separated by commas)
BackgroundCode
Public partial class config: pagebase {Private Static readonly log4net. ilog logger = log4net. logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype); # region page_load protected void page_load (Object sender, eventargs e) {If (! Ispostback) {loaddata () ;}} private void loaddata () {tbxtitle. TEXT = xconfighelper. title; nbxpagesize. TEXT = xconfighelper. pagesize. tostring (); ddlmenutype. selectedvalue = xconfighelper. menutype. tolower () ;}# endregion # region events protected void btnsave_onclick (Object sender, eventargs e) {xconfighelper. title = tbxtitle. text. trim (); xconfighelper. pagesize = convert. toint32 (nbxpagesize. text. trim (); xconfighelper. menutype = ddlmenutype. selectedvalue. tolower (); xconfighelper. saveall (); // refresh the parent page extaspnet. pagecontext. registerstartupscript ("parent. window. location. href = parent. window. location. href; ") ;}# endregion}
Note: after saving the attributes, We need to refresh the parent page to apply the changes. Extaspnet. pagecontext. registerstartupscript is a common function used to register a script to a page.
In the next chapter, we will dynamically create menus in the left area based on the menu type (tree menu or accordion menu) set here.
Download all source code