Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Showing posts with label C# HTML. Show all posts
Showing posts with label C# HTML. Show all posts

Tuesday, March 4, 2008

Prevent wrapping in table cell

Prevent wrapping in table cell. Since the old nowrap method is out of favor, the new method is to use:


<td style="white-space:nowrap"> foo </td>

reference: http://www.thescripts.com/forum/thread468471.html
Note: this also works with a Calendar Extender and TextBox even if the cell is too short.

Sunday, March 2, 2008

Setting up form for HTML Email and Avoiding HttpRequestValidationException

In a previous post I showed you how to set up .NET for email. But what if I want to send it as HTML. I tried and received this error: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client ...

The validation problem is solved by setting the Page attribute Validation="false". But then when I sent the HTML it was received as text.

The solution is to use IsHTML=true In my example, I used a check box:

protected void btnSend_Click(object sender, EventArgs e)
{
string sTo = "jane@foo.com";
string sFrom = ddlFrom.SelectedItem.Text.Trim();
string sSubject = txtSubject.Text.Trim();
string sBody = txtContent.Text.Trim();
lblStatus.Text = "Sending... please wait";
MailMessage msg = new MailMessage(sFrom, sTo, sSubject, sBody);
msg.IsBodyHtml = chkIsHTML.Checked;
SmtpClient mailObj = new SmtpClient("localHost");
mailObj.Credentials = new NetworkCredential("username", "password");
mailObj.Send(msg);
clearTexts();
lblStatus.Text = "Success: Sent message to Jane at " + DateTime.Now.ToLongTimeString() + " Eastern.";

}



References: http://www.hintsandtips.com/ShowPost/131/hat.aspx
http://aspnet.4guysfromrolla.com/articles/080206-1.aspx