Download The Code
AIM : 1.When User Enters A code In Textbox It must Go to An XML window and at the same time Viewable At the Page .
2.There Must Be a Cpatcha In Place sot that We can Know whether It is A bot or Not .
3. Admin must Be able To delete Unwanted Comments .
How : Just Download the CODE
Images :

Procedure :
In Default.aspx write the Following Code :
Note: There must be MSCaptcha.dll in the Bin Folder you can Download it from The Above Link
Well In Default.aspx.cs Write the following Code:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
readXML();
}
protected void butAdd_Click(object sender, EventArgs e)
{
if (txtName.Text == "" || txtUserComment.Text == "" )
lblStatus.Text = "Please complete the form.";
else
{
Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
if (Captcha1.UserValidated)
{
}
else
{
lblStatus.Text = "Invalid Captcha ";
}
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
xmlDoc.Element("Comments").Add(new XElement("Comment", new XElement("Name", txtName.Text),
new XElement("UserComment", txtUserComment.Text)));
xmlDoc.Save(Server.MapPath("People.xml"));
lblStatus.Text = "Comment Successfully Published";
readXML();
}
}
protected void readXML()
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));
var Comments = from Comment in xmlDoc.Descendants("Comment")
select new
{
Name = Comment.Element("Name").Value,
UserComment = Comment.Element("UserComment").Value,
};
litResults.Text = "";
foreach (var Comment in Comments)
{
litResults.Text = litResults.Text + "Name: " + Comment.Name + " ";
litResults.Text = litResults.Text + "Comment: " + Comment.UserComment + " ";
}
if (litResults.Text == "")
litResults.Text = "No Comments";
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="MSCaptcha" namespace="MSCaptcha" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Using AJAX, LINQ and XML together in ASP.NET 3.5 and C#.NET</title>
</head>
<body>
<div align="left" >
<form id="form1" runat="server">
<table style="width:100%;">
<tr>
<td style="margin: 10px">
Comments Posted Alredy --------<br />
<br />
<asp:Literal ID="litResults" runat="server" /></td>
</tr>
</table><br />
<br />
POST A COMMENT :<br />
<table style="width:40%; margin-top: 0px;">
<tr>
<td class="style3">
NAME</td>
<td class="style2">
<asp:TextBox ID="txtName" runat="server" Width="222px" /></td>
</tr>
<tr>
<td class="style4">
COMMENT</td>
<td class="style5">
<asp:TextBox ID="txtUserComment" runat="server" Height="86px" TextMode="MultiLine"
Width="224px" /></td>
</tr>
<tr>
<td class="style3">
CAPTCHA</td>
<td class="style2">
<cc1:CaptchaControl ID="Captcha1" runat="server" CaptchaLength="1"
Width="100px" CaptchaWidth="100" LineColor="Brown" NoiseColor="Azure"
CssClass="me" /> <asp:TextBox ID="txtCaptcha" runat="server" Width="50px"></asp:TextBox> <br />
<br />
<asp:Button ID="butAdd" runat="server" Text="Post Comment" onclick="butAdd_Click" />
<br />
<asp:Label ID="lblStatus" runat="server" ForeColor="#FF3300" />
</td> </tr> </table>
<br /><br /> <br /> <br /> </div> </form>
</body>
</html>
Note: There must be MSCaptcha.dll in the Bin Folder you can Download it from The Above Link
Note: There must Be People.xml in the Same Folder as in that of Code . This Code also works in UserControl .
If there is any Problem Please leave it In Comment
4 comments:
how to remove the comment
Thank u.. awesome
but i want to run this on visual studio 2005 it show an error because vs2005 not support LINQ so
how can i do this in vsual studio 2005
http://forums.asp.net/p/1313885/2607848.aspx
This will help u out , if possible upgrade to a better version of visual studio
Post a Comment