Column Management created in pure asp + language (1)

Source: Internet
Author: User

Http://www.asp888.net bean curd technology station

Yesterday's asx version of the column management and the previous message version of the program since the launch, the response is good, but many netizens have raised new questions, they think that these two programs are actually just simple upgrades of asp files to aspx files, and we do not see the new features of aspx from these programs, bean curd was asked to use the aspx feature to create An aspx version program. Some friends asked that the programming language should not use VB, but the C # statement, in fact, the recommended language of MS is VB, but in order to take care of everyone's desire to learn new knowledge, tofu has launched this purely aspx features + C # Language Production of the column Management Program, the download will be completed soon.

Now let's take a look at this new add. aspx
<% @ Assembly Name = "System. Net" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
<Script language = "C #" runat = server>
Protected void Page_Load (Object Src, EventArgs E ){
SQLDataReader dbRead;
SQLCommand dbComm;
String strSQL;
String strConn;
SQLConnection conn;
Hashtable Cfg = new Hashtable ();
Cfg = (Hashtable) Context. GetConfig ("appsettings ");
StrConn = Cfg ["Conn"]. ToString ();
Conn = new SQLConnection (strConn );
StrSQL = "select * from lanmuclass order by classid ";
DbComm = new SQLCommand (strSQL, conn );
DbComm. ActiveConnection. Open ();
DbComm. Execute (out dbRead );
While (dbRead. Read ()){
// This program is used when the DropDownList display is inconsistent with the Value
ListItem li = new ListItem ();
Li. Text = dbRead ["classname"]. ToString ();
Li. Value = dbRead ["classid"]. ToString ();
SelClass. Items. Add (li );
}
// If the display is consistent with the Value, you can simply do this.

SelFrom. Items. Add ("original ");
SelFrom. Items. Add ("reproduced ");
SelFrom. Items. Add ("Translation ");
SelFrom. Items. Add ("data sorting ");

// If the TextMode attribute is not set in <asp: TextBox, you can also set it like this
// TxtPass. TextMode = TextBoxMode. Password;
}
</Script>
<Html>
<Head>
<Title> add an article </title>
<Link rel = "stylesheet" type = "text/css" href = "/doufu.css">
</Head>
<Body>
<Form action = "doSaveAdd. aspx" method = post>
<Asp: table id = "tableTest" width = 100% GridLines = "Both" Runat = "server" HorizontalAlign = "Center" Font-Name = "Verdana" Font-Size = "8pt" CellPadding = 15 CellSpacing = 0>
<Asp: TableRow runat = server>
<Asp: TableCell width = 20%> </asp: TableCell>
<Asp: TableCell width = 30%> <asp: TextBox id = "txtName" runat = server/> </asp: TableCell>
<Asp: TableCell width = 20%> password </asp: TableCell>
<Asp: TableCell width = 30%> <asp: TextBox id = "txtPass" TextMode = Password runat = server/> </asp: TableCell>
</Asp: TableRow>
<Asp: TableRow runat = server>
<Asp: TableCell width = 20%> Article type </asp: TableCell>
<Asp: TableCell width = 30% colspan = 3> <asp: DropDownList id = selClass runat = server/> </asp: TableCell>
</Asp: TableRow>
<Asp: TableRow runat = server>
<Asp: TableCell width = 20%> publication type </asp: TableCell>
<Asp: TableCell width = 30% colspan = 3> <asp: DropDownList id = selFrom runat = server/> </asp: TableCell>
</Asp: TableRow>
<Asp: TableRow runat = server>
<Asp: TableCell width = 20%> Article Title </asp: TableCell>
<Asp: TableCell width = 30% colspan = 3>
<Asp: TextBox id = "txtTitle" runat = server/>
<Asp: Button id = "do" runat = server text = "OK to add"/>
</Asp: TableCell>
</Asp: TableRow>
<Asp: TableRow runat = server>
<Asp: TableCell width = 20%> Article content </asp: TableCell>
<Asp: TableCell width = 30% colspan = 3> <asp: TextBox id = "txtContent" TextMode = MultiLine rows = 20 cols = 40 runat = server/> </asp: TableCell>
</Asp: TableRow>
</Asp: Table>
</Form>
</Body>
</Html>
The program here is very simple, but he used some special attributes of aspx, And because C # is a case-sensitive language, therefore, you must be very careful when switching from VB to C.
DoSaveAdd. aspx file content:
<% @ Assembly Name = "System. Net" %>
<% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Data" %>
<% @ Import Namespace = "System. Data. SQL" %>
<Script language = "C #" runat = server>
Protected void Page_Load (Object Src, EventArgs E ){
String strConn;
SQLConnection conn;
Hashtable Cfg = new Hashtable ();
Cfg = (Hashtable) Context. GetConfig ("appsettings ");
StrConn = Cfg ["Conn"]. ToString ();
Conn = new SQLConnection (strConn );
String strName = Request. Form ["txtName"]. ToString ();
String strPass = Request. Form ["txtPass"]. ToString ();
If (strName = ""){
Showmsg. Text = "sorry, the user name is a closed project ";
Return;
}
String strSQL;
// Check whether the user and password are correct.
SQLDataReader dbRead;
StrSQL = "select UserPassword from bbsuser where username =" + strName + "";
SQLCommand sqlCmd = new SQLCommand (strSQL, conn );
SqlCmd. ActiveConnection. Open ();
SqlCmd. Execute (out dbRead );
If (! DbRead. Read ()){
Showmsg. Text = "sorry, this user does not exist! ";
Return;
}
If (dbRead ["UserPassword"]. ToString ()! = StrPass ){
Showmsg. Text = "sorry, the user name and password do not match! ";
Return;
}
SqlCmd. ActiveConnection. Close ();
// Password Match. Save the text entered by the user to the database.
// Because it is a demo program, the legality of the title and content is not verified.
String strClassId = Request. Form ["selClass"];
String strSelFrom = Request. Form ["selFrom"];
String strTitle = Request. Form ["txtTitle"];
String strContent = Request. Form ["txtContent"];

StrSQL = "insert into lanmu (classid, title, content, dtime, userid, IsUse, viewnum, selFrom) values (";
StrSQL = strSQL + "" + strClassId + "," + strTitle + "," + strContent + ",";
StrSQL = strSQL + "getdate ()," + strName + ", 0," + strSelFrom + ")";
SqlCmd = new SQLCommand (strSQL, conn );
SqlCmd. ActiveConnection. Open ();
SqlCmd. ExecuteNonQuery ();
// Although the system can automatically close this Command object, you 'd better disable it yourself.
SqlCmd. ActiveConnection. Close ();
}
</Script>
<Html>
<Head>
<Title> add an article </title>
<Link rel = "stylesheet" type = "text/css" href = "/doufu.css">
</Head>
<Body>
<Asp: Label id = showmsg Text = "congratulations, congratulations! Your article has been added to the database! "Runat = server/>
</Body>
</Html>
Actually, this doSaveAdd. the aspx file is actually not needed. We only need to add. it's okay to process the OnClick event on the upload do of aspx. The program is the same. Isn't it better to give you a new option?


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.