ASP. ASP. NET Application Template

Source: Internet
Author: User
When ASP is a beginner, the program can barely be written. However, every time a website page is revised, all source programs will be transplanted. The amount of manpower and energy it consumes is countless, and even the loss is not worth the candle.

Therefore, I dreamed that the code of a large program would be replaced by a few simple characters, so as long as the page is designed to insert this function, it will be OK. In fact, this is also simple. You only need to make the program code that implements this function into a subroutine, and then call the home page.

Many times, in blog China, you may choose many templates or even design them by yourself; or the webmasters who use the pig Feifei Blog have changed their sites not nearly the same ...... All of these are attributed to ASP's use of the template function.

Now, let's take a look at the template and analyze it to feed your friends.

First, if the template needs to be modified online, the database should be used to save the template code.

The so-called template is the standard HTML code designed to be completed, which requiresFunctions implemented by the programWill adoptSpecial string. However, these special strings must be compiled into corresponding functions during display.

1. design the database testmb. MDB
Create a table moban: Field m_id (automatic number, primary keyword); field m_html (Remarks type)

2. Assume that the content code of the first template is

Copy the following code to the m_html field.

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> testmb </title>
</Head>
<Body leftmargin = "0" topmargin = "0">
<Table width = "100%" Height = "100%" border = "0" cellpadding = "5" cellspacing = "2">
<Tr align = "right" bgcolor = "# cccccc">
<TD Height = "20" colspan = "2"> $ cntop $ </TD>
</Tr>
<Tr valign = "TOP">
<TD width = "25%" bgcolor = "# e5e5e5"> $ cnleft $ </TD>
<TD width = "74%" bgcolor = "# f3f3f3"> $ cnright $ </TD>
</Tr>
</Table>
</Body>
</Html>

Note $ cntop $, $ cnleft $, and $ cnright $. They will implement certain program functions.

3. Create the database connection file conn. asp

<%
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("testmb. mdb ")
Conn. Open connstr
%>

4. Create the library file Lib. asp required for special String Conversion

The main function of this file is to make ASP programs that implement certain functions into word programs for convenient calls.

<%
Dim topcode
Sub cntop ()
Topcode = "the current time is :"
Topcode = topcode & now ()
End sub

Dim leftcode, I
Sub cnleft ()
For I = 1 to 5
Leftcode = leftcode & "<p> cnbruce.com"
Next
End sub

Dim rightcode
Sub cnright ()
For I = 1 to 9
Rightcode = rightcode & "<HR color =" & I & ">"
Next
End sub
%>

5. Finally, call the template code in the database to convert special strings.

<! -- # Include file = "conn. asp" -->
<! -- # Include file = "Lib. asp" -->
<%
SQL = "select * From moban where m_id = 1"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 1, 1
Mb_code = RS ("m_html ")
Rs. Close
Set rs = nothing

Cntop ()
Mb_code = Replace (mb_code, "$ cntop $", topcode)
Cnleft ()
Mb_code = Replace (mb_code, "$ cnleft $", leftcode)
Cnright ()
Mb_code = Replace (mb_code, "$ cnright $", rightcode)

Response. Write mb_code
%>

This page is mainly used to display the template code and convert the special code into the corresponding subroutine function.

At this point, the ASP template function is basically complete, and the rest is: create a program page with the template editing function, change the library file to your desired program function ......

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 783511

Application templates in ASP. NET use

1. User Interface

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Using system. text;
Namespace localhost. template background management
{
/// <Summary>
/// Useinterface abstract description.
/// </Summary>
Public class useinterface: system. Web. UI. Page
{
Protected string show_string;
Protected stringbuilder show_string2;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Sqlconnection conn;
Conn = new sqlconnection ("Server = localhost; database = skin; uid = sa; Pwd = ''");
Conn. open ();
Sqldataadapter da = new sqldataadapter ("select skin_html from skinbin where isdefault = 1", Conn );
Dataset DS = new dataset ();
Da. Fill (DS, "skin ");
// Show_string2.append (Ds. Tables ["skin"]. Rows [0] [0]. tostring ());
// Show_string2.replace ("$ show_blogname $", "shadow killer"); // replace the special mark
Show_string = Ds. Tables ["skin"]. Rows [0] [0]. tostring ();
Show_string = show_string.replace ("$ show_blogname $", "shadow killer ");
Response. Write (show_string );
}

# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}

2. Management Background

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Namespace localhost. template background management
{
/// <Summary>
/// Summary of skinmanage.
/// </Summary>
Public class skinmanage: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. DataGrid datagrid2;
 
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
// Place user code here to initialize the page
Sqlconnection conn;
Conn = new sqlconnection ("Server = localhost; database = skin; uid = sa; Pwd = ''");
Conn. open ();
Sqldataadapter da = new sqldataadapter ("select ID, skin_name from skinbin", Conn );
Dataset DS = new dataset ();
Da. Fill (DS, "skin ");
Da. Fill (DS, "skinall ");
// Show_string = Ds. Tables ["skin"]. Rows [0] [0]. tostring ();
Datagrid2.datasource = Ds. Tables ["skinall"]. defaultview;
Datagrid2.databind ();
}

# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Maid + = new system. Web. UI. webcontrols. Maid (this. Maid );
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion

Private void datagrid2_deletecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Try
{
Sqlconnection conn;
Conn = new sqlconnection ("Server = localhost; database = skin; uid = sa; Pwd = ''");
Conn. open ();
String id = "";
Id = E. Item. cells [2]. text;
Sqlcommand comm = new sqlcommand ("Update skinbin set isdefault = 1 where id =" + id, Conn );
Comm. executenonquery ();
}
Catch
{

}
Response. Write ("<SCRIPT> alert ('template changed, please refer to user interface'); </SCRIPT> ");

}
 


}
}

3. Database

If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [skinbin] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [skinbin]
Go

Create Table [DBO]. [skinbin] (
[ID] [int] identity (1, 1) not null,
[Skin_name] [char] (10) Collate chinese_prc_ci_as null,
[Skin_html] [ntext] collate chinese_prc_ci_as null,
[Isdefault] [bit] Null
) On [primary] textimage_on [primary]
Go

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 668003

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.