ASP. net1.1 Development Special template class

Source: Internet
Author: User
It has been several years for web development. I have different understandings in different companies. I recently worked on a blog project. I realized the role of the template class in Web development. At home at night. I always want to create a template class specially designed for ASP. Ne development. So I wrote this template class.

Http://www.93913.com/Edit_html/UploadFile/20065/200652205536669.gif
Just use a picture of this address for Internet Express and other things.
Change the file to the *. rar file. The following is a description file in the file // documentation // introduction:
This template class is designed for three-tier architecture web site development. Stringtempletreplet. dll component
Contains a template class. The template class in the stringtempletreplet namespace can be used on the UI Layer or
To be used in the logic layer. **************************************** * ************************************ Running method:
Create a virtual directory named templet, which refers to the extracted templet folder.
Run the internal retuenstring. aspx, returntext. aspx, writearticon. aspx,
Longloop. ASPX page. The corresponding description is provided on the CS file corresponding to the page.
The first time you open the page, you should keep the delegate object and template file in the cache, so the real speed depends on
After one. **************************************** * ************************************ Principles:
A tag replacement template. The pointer operation in C # is used to find the tag location.
The delegate object refers to the parsing function corresponding to the tag, and uses the static object to cache all the delegate objects.
Cache all template content without changing the template body. You can change the template dynamically. **************************************** * *********************************** Label introduction: the content between {$ and $} is a tag.
For example
{$ Tag Name: parameter 1: parameter 2: parameter 3: character 10 $}
{$ Tag Name: parameter 1: parameter 2: byte 10 $}
{$ Dt [5] [name] $} In a tag, use the following symbol to divide the tag into (TAG parameter) and (command control ).
{$ Tag Name: parameter 1: parameter 2: parameter 3: byte 10 $}
(TAG parameter Section): (Command Control Section) in the two sections, use the comma (,) to separate the tag parameter section and the command control part. The first part is the tag name, is the corresponding name of the tag parsing function, and will be a function parameter later,
The tag parsing function accepts all string-type parameters with 0 to 20 parameters.
Function. The return type is string. Parameters can be written to the tag or dynamically.

Command Control part-currently, there are only two command symbol characters and bytes, followed by a numeric parameter, indicating that the mark is truncated.
The length of the parsing result, for example, 10 bytes.

I will expand other command control symbols in the future.
For details about how tags correspond to functions, see business. for details about the tag usage rules in the CS file, see the call rules in the templet/aa1.htm template. For details, refer to the three aspx pages in the project in writearticon. aspx -- read template parsing Write File used to generate a static page in the news system returntext. aspx -- read template parsing returns a string that is often used to change the appearance of a page,
Skin change page. The template can be changed dynamically. **************************************** **************************************
 
Dynamic tag value: the tag parsing function can accept fixed parameters from the tag. Dynamic parameters can be accepted in three ways.
After the able and hashtable objects are passed as the template class
(Datatable is obtained from the data layer. hashtable is generally a page variable and other variables.) 1. DT [5] [name] ---- the value in the name column of the five rows in the able. The first value is a number,
The second is column name 2. DT [name] ---- the value in the name column of the 0 rows in the able is taken out of the loop,
One parameter represents the column name

---- In the loop, the value of the name column in the able is obtained.
Some rows are determined by the parameters of the loop tag 3. Page [pageid] ----- indicates taking the value of the pageid key in the hashtable object, and returning the string type, for example, {$ two parameter bookmarks: dt [3] [word]: page [userid]:: character 10 $} {$ dt [5] [name] $} {$ dt [name] $} {$ page [pageid] $}

Or

{$ Dt [5] [name]: character 10 $} {$ dt [name]: character 10 $} {$ page [pageid]: character 10 $}

This label directly displays the value ********************************* of the object on the page *************************** **************************************** * ******** call the template class method on the page or in the class: can be called on pages or within a class
 
Generate an object and associate the corresponding tag function parsing class

// Here, we only need to add a business object after this line in new business ().
// Use the interface to implement polymorphism, and the code looks a little troublesome. You only need to 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 attributes
Objilabel. readfilepath = This. server. mappath ("templet/aa1.htm ");

// Write File Path attributes
Objilabel. writfilepath = This. server. mappath ("Page/aa1.html ");

// Obtain the data table object
Objilabel. labeldatatable = Ds. Tables [0];

// Use the hashtable object to pass the variables on this page to the near template class.
Objilabel. labelhashtable = HT;

Three replicas can be implemented.
// Start to replace the Write template
Objilabel. laberreplet ();
// Return the resolution result
String AA = objilabel. laberreplettext ();
// Return the parsing result. The template string is directly accepted. For details, refer to the retuenstring. CS file.
String AA = objilabel. laberrepletstring ();

For details, refer to the CS files of these two files.
Writearticon. aspx -- read template parsing Write File used to generate static page news system returntext. aspx -- read template parsing returns string with and write pages that often change the appearance
************************************ **************************************** Tag function Association: for details, see business. CS files

Add the following code to the static constructor of the class corresponding to the logic layer.
// Call the static constructor to delegate the tag execution function to the static hash table.
// This method must be executed
Static business ()
{
Business _ this = new business ();

Functionlist. objfunctionhashtable. Add ("No parameter bookmarks", new keyitemdelegate (New userdelegate. run_0 (_ this. Show), 0 ));

Functionlist. objfunctionhashtable. Add ("one parameter bookmarks", 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 ));


// Associate bookmarks with execution functions. Put it in the static constructor of the bookmarks parsing class. It is to make full use of objects in the memory, not every time
// The Public String tag (string aa) function corresponding to the "one-parameter bookmarks" character is used to add key and value to the hash table
// ("A parameter bookmarks", new keyitemdelegate (New userdelegate. run_1 (_ this. Tag), 1 ));
// Tag Name |
// Use run_1 to delegate a parameter. |
// Corresponding tag execution function |
// Write number 1 for a parameter

// There are 0 or more examples above
}

For details, see the business. CS file.

**************************************** * ************************************* In-tag Loop loop introduction:
Some special symbols can be used in the tag to implement non-nested loop loops //------------------------------------------------------------------------
{$ Loop (3,0, Alter) $} // three rows are displayed, starting from row 0. If there are alternate columns, run the alternate column {$ blockitem $} // The default loop row,

<TD bgcolor = "#33 CCFF"> title: {$ dt [5] [name] $}, Author: {$ a parameter: DT [dddf] $} </TD>

{$/Blockitem $}

{$ Blockalteritem $} // when there is no default row tag pair for alternating loop rows, there is an alternating loop tag pair. Use the alternating tag pair as the default row tag pair.

<TD bgcolor = "# ff6699"> title: {$ dt [5] [name] $}, Author: {$ a parameter: dt [dddf] $} </TD>

{$/Blockalteritem $}

{$ Blockpatch $} // when the number of rows to be cyclic is greater than the number of rows in the datatable, use the content here to add the display. If no "Supplemental" tag pair exists. When the number of rows displayed is greater than the number of rows in the datatable, only the number of rows in the datatable is displayed.

<TD bgcolor = "#33 CCFF"> supplement (the tag can also be used inside) </TD>

{$/Blockpatch $}

{$ Blockalterpatch $} // No tag pair is added, and there are alternate tag pairs. When adding a tag pair

<TD bgcolor = "# ff6699"> alternate addition (tags can also be used inside) </TD>

{$/Blockalterpatch $}
{$/Loop $} // The End of the loop
//--------------------------------------------------------------
 
{$ Blockitem $ }{$/blockitem $}: the default cyclic row label pair {$ blockalteritem $ }{$/blockalteritem $ }: alternating loop row tag pairs {$ blockpatch $ }{$/blockpatch $}: added row tag pairs {$ blockalterpatch $ }{$/blockalterpatch $} by default }: alternate adding line label pair //------------------------------------------------------
 
If only the default loop row can be added, the {$ blockitem $} tag is not added.
For example
{$ Loop (3,0, Alter) $}
<Tr> <TD >{$ function tag $} </TD> </tr>
{$/Loop $}
And
{$ Loop (3,0, Alter) $}
{$ Blockitem $} <tr> <TD >{$ function tag $} </TD> </TR >{$/blockitem $}
{$/Loop $}
Yes indicates the same effect
 
 
//-------------------------------------------------------------
 
 
{$ Loop (3,0, Alter) $}
{$ Blockalterpatch $}
<Tr> <TD >{$ function tag $} </TD> </tr>
{$/Blockalterpatch $}
{$/Loop $}
If only the alternating loop row label Pair does not have the default cyclic row label pair, the alternating loop row label pair is automatically converted
Default cyclic row label pair
 
 
//--------------------------------------------------------------
 
{$ Loop (3,0, Alter) $}
{$ Blockalterpatch $}
<Tr> <TD >{$ function tag $} </TD> </tr>
{$/Blockalterpatch $}
{$/Loop $}
If there is no default add row tag pair for the alternate add row tag pair, the alternate add row tag pair is automatically converted
Default cyclic row label pair

 
 
**************************************** * ********************************** Loop parameter description:
{$ Loop (3,0, Alter) $}
There are three parameters in the loop. You can reduce the first parameter as appropriate:
3: loop 3 times, not indicating all the second parameters of the Loop:
2: Starting from 2, the third parameter from 0 is not indicated:
Alter: Alternate
Noalter}
Number of rows in the cyclic able
Starting from row 0, a supplement is displayed. ****************************************. It mainly optimizes the cycle.
Currently, the number of rows in a loop is 50 thousand-300 milliseconds. **************************************** * *********************************** It is recommended that the template not be larger than 85 k, be careful to become a large object. We recommend that there be no more than 919 page templates for second generation objects and no more than 1597 corresponding function labels. I am very happy to see the growth of the template class along with my own understanding. **************************************** *************************************
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.