您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
一个ASP.NET+XML留言本例子
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:02:33
tor.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>

上一页  [1] [2] 


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |