View Single Post
  #3 (permalink)  
Old September 10th, 2007, 04:44 AM
ostwald ostwald is offline
Authorized User
 
Join Date: Jun 2007
Location: hyderabad, AndhraPradesh, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Pete,
Thanx fo ur reply. I achieved the application by parsing. I didn'y use XHTML. I used html text as string and then parsed it to generate the required criteria. Herez the code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" ValidateRequest="false" %>
<%@ Import namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>


<!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 runat="server">
    <title>Untitled Page</title>
</head>
<script language="C#" type="text/C#" runat=server >
private void Post_Text(object sender, EventArgs e)
{

if(mess.Text!="")
{

if(parse.Checked)
{

if(htmlpost.Checked)
{

postmess.Text=parsetext(mess.Text,false) ;
}
else
{

//postmess.Text=parsetext(mess.Text,true) ;
//}
//}
//else
//{

postmess.Text=mess.Text ;
String s = "Select * from htmln";
SqlConnection con = new SqlConnection("Data Source=KIRAN;Initial Catalog=TrylahNewLayout;Persist Security Info=True;User ID=sa;Password=sa123");
SqlDataAdapter da = new SqlDataAdapter(s,con);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet("htmln");
da.Fill(ds, "htmln");

DataRow row = ds.Tables["htmln"].NewRow();
row["doc"] = postmess.Text;
ds.Tables["htmln"].Rows.Add(row);
da.Update(ds, "htmln");



}
}

public string parsetext(string text, bool allow)
{

StringBuilder sb = new StringBuilder(text) ;

sb.Replace(" "," &nbsp;");

if(!allow)
{

sb.Replace("<","&lt;") ;
sb.Replace(">","&gt;") ;

sb.Replace("\"","&quot;");
}

StringReader sr = new StringReader(sb.ToString());
StringWriter sw = new StringWriter();

while(sr.Peek()>-1)
{

string temp = sr.ReadLine();

sw.Write(temp+"<br>") ;
}

return sw.GetStringBuilder().ToString();
}
</script>
<body>


<center>
<br>
<form runat=server ID="Form2">
<table border=1>
<tr>
<td valign=top>Result</td>
<td>
<asp:label text="&nbsp;" id=postmess runat=server Width="68px" />
</td></tr>
<tr><td valign=top>Enter Message </td>
<td><asp:textbox Columns="50" Rows="20" TextMode="MultiLine" id=mess runat=server /></td></tr>
<tr><td colspan=2 style="height: 28px"><asp:button onClick="Post_Text" text="Generate!" runat=server ID="Button1" /></td></tr>
</table>
</form>
</center>
</body>
</html>