亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

一個ASP.NET+XML留言本例子

2019-11-18 20:47:01
字體:
來源:轉載
供稿:網友
viewpost.aspx--察看提交的留言
viewguestbook.aspx--察看所有留言
Header.inc
guestpost.aspx--留言表單及xml寫操作
Footer.inc
Guest.xml--XML數據

源代碼如下:

viewguestbook.aspx
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C<%-- Needed Assembiles --%>

<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script language="C //run the script when the Page is Loaded
public void Page_Load(Object sender, EventArgs e)
{
// an label , its use stated later
tryagain :

//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile = "db/guest.xml" ;

//try-Catch block to read from an XML file
try
{
//make an instance to the XMLDataDocument class
//this class can read from an xml file in and ordered format
XmlDataDocument datadoc = new XmlDataDocument();

// Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader(Server.MapPath(datafile)));

//Databind the first table in the Dataset to the Repeter
MyDataList.DataSource = datadoc.DataSet.Tables[0].DefaultView;
MyDataList.DataBind();

//free up the XML file to be used by other PRograms
datadoc=null;


}
catch(IOException ed)
{
// Here I am for now trying to overcome a bug in my guestbook exapmle
//the Bug is that only one class can either read or write to my XML
// data file at a time.
//If the file is being used my some some other page (eg the guest book viewing page)
// then an IOException will be thrown
// So to handle such situtations what we do is that
// If an IOException is thrown the page goes again to the tryagain label
//and tries to write again into the xml file
//this goes on till finally the resource is freed and the xml file is written to.

goto tryagain ;
}
catch (Exception edd)
{
//catch any other exceptions that occur
errmess.Text="Cannot read from XML file because "+edd.ToString() ;
}



}


</script>
<LINK href="mystyle.CSS" type=text/css rel=stylesheet>

</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" rightmargin="0">
<!-- <asp:label id="errmess" text="" style="color:<br>
<h3 align="center" class="newsbody">My Guestbook.</h3>
<ASP:Repeater id="MyDataList" runat="server">

<template name="headertemplate">

<table class="mainheads" width="100%" style="font: 8pt verdana">
<tr style="background-color: <th>
Name
</th>
<th>
Country
</th>
<th>
Email
</th>
<th>
Comments
</th>
<th>
Date/Time
</th>
</tr>

</template>

<template name="itemtemplate">

<tr style="background-color: <td>
<% </td>
<td>
<% </td>
<td>
<% </td>
<td>
<% </td>
<td>
<% </td>
</tr>

</template>

<template name="footertemplate">

</table>

</template>

</ASP:Repeater>

<!-- </body>
</html>


viewpost.aspx
<%@ Import Namespace="System" %>
<%@ Page Language="C<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script language="C //execute this script when the page loads
void Page_Load(Object Src, EventArgs E)
{
//if the page is called from anothe page
if (!Page.IsPostBack) {
//get the diffrent Parameters from the querry string and store it
//to respective Labels
NameLabel.Text = Request.Params["Name"];
CountryLabel.Text= Request.Params["Country"] ;
EmailLabel.Text=Request.Params["Email"];
CommentsLabel.Text=Request.Params["Comments"] ;
}
if(Page.IsPostBack)
{
//else display an error
errmess.Text="This Page Cannot be called directly. It has to be called from the Guestbook posting page." ;
}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- <asp:label id="errmess" text="" style="color: <center>
<h2 class="newsbody"><b>Thank You , for posting in My GuestBook.</b></h2>
<table align=center width="60%" border="0" cellspacing="2" cellpadding="1" >
<tr class="titheading"><td colspan="2">The information You Posted!</td></tr>
<tr class="newsbody">
<td>Name :</td>
<td><asp:label id="NameLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>Country :</td>
<td><asp:label id="CountryLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>E-mail :</td>
<td><asp:label id="EmailLabel" text="" runat="server"/></td>
</tr>
<tr class="newsbody">
<td>Comments :</td>
<td><asp:label id="CommentsLabel" text="" runat="server" /></td>
</tr>
</table>
<br>
<h4 class="newsbody"><a href="viewguestbook.aspx">Click here </a> to view GuestBook.</h4><br>
</center>
<!--
</body>
</html>


guestpost.aspx

<%@ Import Namespace="System" %>
<%@ Page Language="C<%@ Import Namespace="System.IO" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%-- These are the imported assembiles and namespaces need to run the guest book --%>

<html>

<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script Language="C ///<summary>
/// This methord is called when the submit button is clicked
///</summary>
public void Submit_Click(Object sender, EventArgs e)
{
//A label need to the goto statement explained below
tryagain :

//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile = "db/guest.xml" ;

//put the posting code within a Try-Catch block
try{

//proceed only if all the required feilds are filled-in
if(Page.IsValid&&Name.Text!=""&&Country.Text!=""&&Email.Text!=""){

errmess.Text="" ;

//make an instance of the class XmlDocument
XmlDocument xmldocument = new XmlDocument() ;

//load the xml file you will use as your database.
//Since we are working on a server we have to use 'Server.MapPath()'
//to mape the path to the database file

xmldocument.Load(Server.MapPath(datafile)) ;

//make an instance of DocumentNavigator class which will help us to
//navigate in the loaded XML data file.
DocumentNavigator navigator = new DocumentNavigator(xmldocument) ;

//below code is very significant as it navigates through the XML document and
//stores the required values (ps: read this code carefully)

//first move to the xml documents elements (in my xml file this will come to the 'Guests' Node
navigator.MoveToDocumentElement() ;

//then insert First element (FirstChild) which will contain all the information
// of a single guest posting
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element, "Guest","","") ;

//Insert the Element of Name as the First node of 'Guest'
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element, "Name","","") ;
//This is important to specify what kind of Value will the Name element contain
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Name","","") ;
//assign the Name element the Value from the .Text property of the TextBox
navigator.Value=Name.Text ;

//Go back to the Parent Node ie 'Guest'
navigator.MoveToParent() ;

//Insert another Element 'Country' After the FirstChild ie. after the 'Name' node.
navigator.Insert(TreePosition.After, XmlNodeType.Element,"Country","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Country","","") ;
navigator.Value=Country.Text ;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After,XmlNodeType.Element,"Email","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Email","","") ;
navigator.Value=Email.Text;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After,XmlNodeType.Element,"Comments","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"comments","","") ;
navigator.Value=Comments.Value ;
navigator.MoveToParent() ;

navigator.Insert(TreePosition.After, XmlNodeType.Element,"DateTime","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"DateTime","","") ;
//set the Date time stamp of the entry
DateTime now = DateTime.Now ;
navigator.Value=now.ToShortDateString()+" "+now.ToShortTimeString() ;

//after making the necessary changes we Save the chenges to the Xml Document
xmldocument.Save(Server.MapPath(datafile)) ;
//free up the XML file from the Document file so that other programs can use it
xmldocument=null ;

//Build a custom querry sending the data posted to another page for display
//since it is a querry we have to encode it in UTF8 format
String QueryString ="Name="+ System.Web.HttpUtility.UrlEncodeToString(Name.Text, System.Text.Encoding.UTF8);
QueryString +="&&Country="+ System.Web.HttpUtility.UrlEncodeToString(Country.Text, System.Text.Encoding.UTF8);
QueryString +="&&Email="+ System.Web.HttpUtility.UrlEncodeToString(Email.Text, System.Text.Encoding.UTF8);
QueryString +="&&Comments="+ System.Web.HttpUtility.UrlEncodeToString(Comments.Value, System.Text.Encoding.UTF8);

//go to the page viewpost.aspx and append the querry string at its end.
Page.Navigate("viewPost.aspx?" + QueryString);

}
else
{
//if any of the Feilds are kept empty show an error message
errmess.Text="Fill in all the required feilds of the Guestbook." ;

}
}
catch(IOException ed)
{
// Here I am for now trying to overcome a bug in my guestbook exapmle
//the Bug is that only one class can either read or write to my XML
// data file at a time.
//If the file is being used my some some other page (eg the guest book viewing page)
// then an IOException will be thrown
// So to handle such situtations what we do is that
// If an IOException is thrown the page goes again to the tryagain label
//and tries to write again into the xml file
//this goes on till finally the resource is freed and the xml file is written to.
goto tryagain ;
}
catch (Exception edd)
{
//catch any other exception that occur
errmess.Text="Cannot write to XML file because "+edd.ToString() ;

}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<%-- Include a header file 'header.inc' --%>
<!-- <br>
<h3 align="center" class="newsbody">Guestbook Post Page.</h3>
<br>
<asp:label id="errmess" text="" style="color: <form runat="server">
<table border="0" width="80%" align="Center">
<tr >
<td class="newsheading"><b>Sign-in My GuestBook</b></td>
<td class="newsheading">&nbsp;</td>

</tr>
<tr class="newsbody" >
<td>Name :</td>
<td ><asp:textbox text="" id="Name" runat="server" />&nbsp;&nbsp;&nbsp;<font color=
</tr>
<tr class="newsbody">
<td>Country :</td>
<td><asp:textbox text="" id="Country" runat="server"/>&nbsp;&nbsp;&nbsp;<font color=
</tr>
<tr class="newsbody">
<td>E-Mail :</td>
<td><asp:textbox test="" id="Email" runat="server"/>&nbsp;&nbsp;&nbsp;<font color=
</tr>
<tr class="newsbody">
<td>Comments :</td>
<td><textarea id="Comments" cols="25" rows="4" runat="server" /></td>

</tr>
<tr class="newsbody">
<td colspan="2" >
<asp:Button class="newsheading" id="write" Text="Submit" onClick="Submit_Click" runat="server"/></td>

</tr>
</table>
</form>
<br>
<h4 class="newsbody"><a href="viewguestbook.aspx">Click here </a> to view GuestBook.</h4><br>
<!-- </body>
</html>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品视频一区国模私拍| 欧美日韩午夜视频在线观看| 色综合久久88| 亚洲www视频| 欧美性猛交xxxx黑人| 懂色aⅴ精品一区二区三区蜜月| 亚洲人成在线播放| 久久91精品国产91久久久| 亚洲a级在线播放观看| 欧美与黑人午夜性猛交久久久| 亚洲国产成人在线视频| 成人h片在线播放免费网站| 97国产精品视频| 国产99久久精品一区二区 夜夜躁日日躁| 国产精品美女主播在线观看纯欲| 久久久黄色av| 日韩免费在线视频| 91午夜理伦私人影院| 成人亲热视频网站| 97高清免费视频| 中文字幕在线看视频国产欧美| 亚洲美女av在线| 欧美劲爆第一页| 国产成人精品a视频一区www| 日韩有码在线视频| 亚洲精品美女在线观看| 欧美精品第一页在线播放| 国产精品亚洲欧美导航| 7777精品久久久久久| 超碰97人人做人人爱少妇| 色视频www在线播放国产成人| 青青草一区二区| 欧美激情亚洲视频| 欧美特级www| 一夜七次郎国产精品亚洲| 久久亚洲精品中文字幕冲田杏梨| 欧美亚洲国产视频小说| 亚洲aa在线观看| 欧美性xxxxx极品| 亚洲欧洲国产伦综合| 国内精品模特av私拍在线观看| 国产免费久久av| 亚洲深夜福利视频| 国产成人精品视频在线| 亚洲激情久久久| 亚洲男子天堂网| 91在线观看免费| 欧美极度另类性三渗透| 欧美日韩加勒比精品一区| 亚洲美腿欧美激情另类| 欧美日韩在线另类| 亚洲一区二区在线| 日韩av影视在线| 亚洲japanese制服美女| 欧美日韩国产综合视频在线观看中文| 国产精品久久久久久久一区探花| 亚洲a∨日韩av高清在线观看| 91视频8mav| 精品久久久久久久大神国产| 国产精品午夜一区二区欲梦| 国产日本欧美一区二区三区在线| 久久久91精品国产| 亚洲精品www久久久久久广东| 美女精品久久久| 国产欧美日韩免费看aⅴ视频| 26uuu亚洲伊人春色| 色综合天天综合网国产成人网| 亚洲人精选亚洲人成在线| 日本韩国在线不卡| 日韩中文字幕不卡视频| 精品国产一区二区三区四区在线观看| 91国语精品自产拍在线观看性色| 亚洲精品中文字幕有码专区| 中国人与牲禽动交精品| 少妇高潮久久久久久潘金莲| 一区二区三区精品99久久| 欧美视频在线观看免费网址| 在线亚洲午夜片av大片| 精品国产一区久久久| 激情av一区二区| 欧美在线视频a| 亚洲第一区在线观看| 欧美激情影音先锋| 欧美超级免费视 在线| 麻豆国产va免费精品高清在线| 精品国产福利视频| 欧美最猛性xxxxx亚洲精品| 18一19gay欧美视频网站| 中文字幕国产亚洲2019| 在线看国产精品| 国产精品永久免费视频| 亚洲黄色在线看| 国产suv精品一区二区三区88区| xxxxx成人.com| 欧美福利小视频| 日韩成人高清在线| 亚洲第一网站免费视频| 青青久久av北条麻妃海外网| 欧美大人香蕉在线| 欧美日韩亚洲一区二| 亚洲精品国产精品自产a区红杏吧| 欧美综合国产精品久久丁香| 欧美午夜宅男影院在线观看| 97av在线影院| 国产丝袜一区二区三区免费视频| 欧美亚洲视频在线看网址| 久久久久久久久久久国产| 国产精品久久久久免费a∨大胸| 亚洲新中文字幕| 一区二区在线视频| 一区国产精品视频| 亚洲欧美日韩一区二区在线| 国产精品福利片| 国产99视频在线观看| 日本高清+成人网在线观看| 久久视频中文字幕| 亚洲国产精品久久久久秋霞不卡| 欧美日韩国产中字| 欧美激情在线视频二区| 一区二区三区日韩在线| 国外成人在线视频| 国产日韩欧美中文在线播放| 欧美激情第一页xxx| 色综合视频一区中文字幕| 国产亚洲xxx| 91精品一区二区| 91亚洲精品在线观看| 欧美一区二粉嫩精品国产一线天| 国产成人短视频| 日韩专区在线观看| 精品久久久国产| 亚洲国产精品久久久久久| 国产丝袜精品第一页| 欧美一级视频在线观看| 一区二区三区无码高清视频| 国产免费成人av| 亚洲国产天堂久久综合网| 欧美—级a级欧美特级ar全黄| 国产成人免费91av在线| 亚洲三级 欧美三级| 午夜欧美大片免费观看| 国产精品福利观看| 亚洲国产中文字幕在线观看| 国产欧美亚洲精品| 91视频九色网站| 91chinesevideo永久地址| 亚洲一区二区久久久| 一个人看的www欧美| 日韩在线免费高清视频| 国产97在线|亚洲| 国产精品久久久久久久久久久久久久| 日韩精品中文在线观看| 精品性高朝久久久久久久| 亚洲xxxx做受欧美| 欧美猛交免费看| 免费不卡欧美自拍视频| 国产精品久久久久一区二区| 精品二区三区线观看| 国产丝袜一区二区| 久久久精品亚洲| 欧美一级视频一区二区| 成人网中文字幕| 欧美日韩亚洲高清| 国产精品aaa|