asp.net1.1 development of Special template classes

Source: Internet
Author: User
Tags constructor contains execution hash implement numeric value variables tag name
asp.net| templates

Web development has been done for several years. I have different knowledge in different companies. Recently do blog project. I recognize the role of template classes in Web development. Himself at home at night. Always want to be able to do a specialized for asp.ne development and design template class. So I wrote this template class.

Download Address point this


Rename the downloaded 500sea.txt file to the Templet.rar file and open it.

If you open
Http://img.club.163.com/images/user/other/500sea
No prompts for 500sea.txt file download. Then use the Internet Express to wait for this address.
Just change the 500sea.txt file down to *.rar file.

Here is a description of the file inside

//----------------------------------------------//

Introduced:
This template class is written for development of a three-tier schema Web site. StringTempletReplet.dll components
Contains the template class. Template classes within the Stringtempletreplet namespace can be used at the UI layer or
To use in the logical layer.
***************************************************************
How to run:
Create a virtual directory named Templet the Templet folder after the decompression
Running inside the retuenstring.aspx,returntext.aspx,writearticon.aspx,
Longloop.aspx page. On the page corresponding to the CS file on the corresponding instructions.
The first time you open the page should be to keep the delegate object and template file into the cache, so the real speed is to see the first
One after the other.
************************************************************
Principle Introduction:
A template for label substitution. Use the pointer operation in C # to find the label location.
The delegate object is used to refer to the corresponding analytic function of the label and to cache all delegate objects with static objects.
Caches all template contents without changing the body of the template. You can change the template dynamically.
************************************************************
Label Introduction:
Label the contents between pairs of special symbols {$ and $}
Such as
{$ label name: Parameter 1: Parameter 2: Parameter 3:: Character 10$}
{$ tag name: Parameter 1: Parameter 2:: Bytes 10$}
{$dt [5][name]$}
Inside the label through:: Symbol to divide the label (tag parameters) and (Command control part) two fast
{$ label name: Parameter 1: Parameter 2: Parameter 3:: Bytes 10$}
(label parameter part):: (Command control section)
In these two parts, divide the label parameter part and the command control part.
The label parameter part---the first one for the label signature, that is, the corresponding name of the tag resolution function, and then the parameter of the function.
The label resolution function accepts that all parameter types are of type string and the number of arguments is 0--20.
function that returns the type string. Parameters can be written to die on the label, or they can be written dynamically.

Command-Control Section---now has only two command symbol characters and bytes, followed by a numeric parameter that represents the Intercept label
The length of the check resolution result, such as character 10 byte 10.

I will later extend the other command control symbols.

Label and function corresponding see Business.cs file description
Label specific use rules please see templet/templet/aa1.htm template description
For specific calling rules, look at these three ASPX pages in the project
Writearticon.aspx--Read template parsing write file to create a static page of the news system
Returntext.aspx--Read template parsing return string use and write pages that often change the appearance of
Change the skin of the page. You can change the template dynamically.
Retuenstring.aspx--accepts the label string and returns the result of the resolution. Commonly used with Ajax.
*************************************************************

Label Dynamic Value:
The label parsing function can accept the fixed parameters from the tag. There are three different ways to accept dynamic parameters
After passing the Datatable and Hashtable objects like a template class
(Datatable gets from the data layer, Hashtable is typically page variables and other variables)
1. Dt[5][name]----Represents the number on the 5 row Name column of the DataTable, the first digit,
The second one is the column name
2. Dt[name]----represents the values on the 0-row Name column in the DataTable outside the Loop loop.
A parameter represents the column name

----represents a value on the Name column in the DataTable within the Loop loop, taking the
Some rows are determined by the parameters of the loop tag
3. Page[pageid]-----Represents a numeric value on the PageID key within the Hashtable object, returning a string type
Such as {$ two parameters bookmark: Dt[3][word]:p Age[userid]:: Character 10$}

{$dt [5][name]$}   {$dt [name]$} {$page [pageid]$}

Or

{$dt [5][name]:: Character 10$}  {$DT [name]:: Character 10$} {$page [PageID]:: Character 10$}

A label like this indicates that the value of an object is displayed directly on the page
************************************************************
To call the template class method within a page or class:
Can be called within a page or class

Generating objects, associating corresponding tag functions to parse classes


Right here, I just need to be behind this line. New Business () a Business class object.
Using interfaces to implement polymorphism, the code looks a bit cumbersome. When you use it, just modify the last "new Business ()" For your own class that contains the tag parsing function.
Ilabelanalystart objilabel= (Ilabelanalystart) New Templetreplet (New Business ());

Read template path properties
Objilabel.readfilepath=this. Server.MapPath ("templet/aa1.htm");

Write File path properties
Objilabel.writfilepath=this. Server.MapPath ("page/aa1.html");

Get Data Table objects
Objilabel.labeldatatable=ds. Tables[0];

Bring the variables on this page to the template class with Hashtable objects
OBJILABEL.LABELHASHTABLE=HT;

You can then implement three replacements
Start replacing write template
Objilabel.laberreplet ();
Returns the result of the resolution
String Aa=objilabel.laberreplettext ();
Returns the result of the parse, which is a direct acceptance of the template string, see RetuenString.cs file
String aa=objilabel.laberrepletstring ();

See the CS files of these three files in detail
Writearticon.aspx--Read template parsing write file to create a static page of the news system
Returntext.aspx--Read template parsing return string use and write pages that often change appearance
Change the skin of the page
Retuenstring.aspx--accepts the label string to return the parse result. Common and Ajax

*********************************************************
Label Function Association:
Please see Business.cs file in detail

In the static constructor of the class corresponding to the logical layer, add the following code.

Call the static constructor and put the tag in the static hash table by executing the function delegate
This method must be implemented
Static Business ()
{
Business _this=new Business ();

FUNCTIONLIST.OBJFUNCTIONHASHTABLE.ADD ("No parameter Bookmark", New Keyitemdelegate (New Userdelegate.run_0 (_this.show), 0));

FUNCTIONLIST.OBJFUNCTIONHASHTABLE.ADD ("One parameter bookmark", New Keyitemdelegate (New Userdelegate.run_1 (_this.tag), 1));

FUNCTIONLIST.OBJFUNCTIONHASHTABLE.ADD ("Two parameter bookmarks", New Keyitemdelegate (New Userdelegate.run_2 (_this.tag_two), 2));


Bookmarks and execution functions are associated. Into the static constructor of the bookmark resolution class. is to be able to fully use objects in memory, not every time
The "one parameter bookmark" character corresponds to the public string tag (string aa) function pattern to add key and value to the hash table
("One parameter bookmark", New Keyitemdelegate (New Userdelegate.run_1 (_this.tag), 1));
Label name |   | |
A parameter is used as a run_1 delegate. | |
Corresponding Label execution function |
One parameter to write number one

0 or more above have a corresponding example
}


Please see Business.cs file in detail

***********************************************************
Introduction to the loop loop in the tag:
A non-nested loop loop can be implemented with some special symbols inside the label


//-------------------------------------------------------------
{$loop (3,0,alter) $}//show three rows, starting with 0 rows, alternating columns if there is alternating column
{$BlockItem $}//default loop line,

&LT;TD bgcolor= "#33ccff" > title: {$dt [5][name]$}, Author: {$ A parameter:dt[dddf]$}</td>

{$/blockitem$}


{$BlockAlterItem $}//alternate cycle line there is no default row label pair, there are alternating tag pairs. Just put the alternating tabs on when the default row label

&LT;TD bgcolor= "#ff6699" > title: {$dt [5][name]$}, Author: {$ A parameter:dt[dddf]$}</td>

{$/blockalteritem$}


{$BlockPatch $}///When the number of rows to be cycled is greater than the number of rows in the DataTable, use this to supplement the display. If there is no "supplemental" label pair. The number of rows in the DataTable is displayed when the number of rows is greater than the number of rows in the DataTable

&LT;TD bgcolor= "#33ccff" > Supplements (can also use tags) </td>

{$/blockpatch$}


{$BlockAlterPatch $}//No supplemental label pairs, there are alternate supplemental label pairs. Just add the alternate label to the

&LT;TD bgcolor= "#ff6699" > Alternate supplement (inside also can use label) </td>

{$/blockalterpatch$}

{$/loop$}//Loop End
//-------------------------------------------------------

{$BlockItem $} {$/blockitem$}: The default loop row label
{$BlockAlterItem $} {$/blockalteritem$}: Alternating loop row labels to
{$BlockPatch $} {$/blockpatch$}: Default supplemental Row label to
{$BlockAlterPatch $} {$/blockalterpatch$}: Alternate supplemental row label to

//------------------------------------------------------

If only the default loop row can not add {$BlockItem $} label to
Such as
{$loop (3,0,alter) $}
<tr><td>{$ function Label $}</td></tr>
{$/loop$}
And
{$loop (3,0,alter) $}
{$BlockItem $}<tr><td>{$ function label $}</td></tr>{$/blockitem$}
{$/loop$}
is to represent the same effect


//-------------------------------------------------


{$loop (3,0,alter) $}
{$BlockAlterPatch $}
<tr><td>{$ function Label $}</td></tr>
{$/blockalterpatch$}
{$/loop$}
If only the alternating loop row label pair does not have the default loop row label pair then the alternating loop row label pairs are automatically converted to
The default loop row label


//-----------------------------------------------

{$loop (3,0,alter) $}
{$BlockAlterPatch $}
<tr><td>{$ function Label $}</td></tr>
{$/blockalterpatch$}
{$/loop$}
If only the alternating complement row label pair does not have the default supplemental row label pair, the alternate supplementary row label pair will be automatically converted to
The default loop row label

***********************************************************

Loop parameter Description:
{$loop (3,0,alter) $}
A total of three parameters on the loop can be appropriately reduced
First parameter:
3: Circulation 3 times, no expression loop all
Second parameter:
2: Starting from 2, no indication starting from 0
Third parameter:
Alter: Alternating
Noalter: Does not alternate, does not indicate that the default is alternating, so alter plus does not add is the same
If all three arguments are not written, at least one pair of empty brackets {$loop () $}
Represents the number of rows within a loop DataTable
Starting with line 0, the supplement is shown.
*********************************************************

have updated a bit. The main is to optimize the cycle.
The table that loops 50,000 rows now takes 300-400 milliseconds.


*********************************************************
Recommended template should not be greater than 85k, be careful to become a large size object. That's a second-generation object.
The recommended page template is less than or equal to 919, and the corresponding function label does not suggest more than 1597.
It's nice to see the template class growing with my own knowledge.

*********************************************************



Related Article

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.