We help IT Professionals succeed at work.

vbcrlf not working on aspx page

I have the following code snippet within a aspx page.  I want the text to be on two lines.  I have seemed to have tried everything to get this to do a vbcrlf.  Here is the lastest attempt.  Can anyone tell me why it doesnt work and how to make it work.  I have used vbcrlf instead and still everything is on the same line.



<head>
<script type="VB" runat="server" > 
 
Sub submit(s As Object, e As EventArgs) 
	
	SendConfirmation
	
End Sub 
Private Function SendConfirmation()
	dim message as string
	Dim nl As String = "%0D%0A"
	dim objMail as new mailmessage()
	message = "Your email message has been received and you will receive a response shortly" & nl & "Thank You for contacting TheApartmentGallery.com"
	objmail.to = txtemailaddress.text
	objmail.from = "Webmaster@theapartmentgallery.com"
	objmail.subject = "Auto Response From the Apartment Gallery"
	objmail.body = message
	objmail.cc = "bkatherman@theapartmentgallery.com"
	smtpMail.send(objMail)
  	SERVER.EXECUTE("sent.aspx")
 
End Function

Open in new window

Comment
Watch Question

Commented:
In HTML, you indicate a new line using <br />

message = "Your email message has been received and you will receive a response shortly.<br />Thank You for contacting TheApartmentGallery.com"
Commented:
Have u tried
message = "Your email message has been received and you will receive a response shortly" & vbCrLf & "Thank You for contacting TheApartmentGallery.com"
	

Open in new window

Commented:
Sorry, it's a mail message...  You need to enter real line break instead of URL encoding it.

message = "Your email message has been received and you will receive a response shortly" & Environment.NewLine() & "Thank You for contacting TheApartmentGallery.com"




Commented:
If that fails, then you would need to use

objmail.BodyFormat = MailFormat.Html

and encode the line as

message = "Your email message has been received and you will receive a response shortly<br />Thank You for contacting TheApartmentGallery.com"

The thing is that many SMTP servers will disallow hard line breaks in text format.


Also watch out for Outlook removing line breaks - look at the top of the message to check this.

Author

Commented:
this code is wrapped around the <script type="VB" runat="server" > script.  So its in vb code.  No of the suggestions have worked.  I am using vb script on a aspx page.   Still no go.  

Commented:
What happened when you tried this:

objmail.BodyFormat = MailFormat.Html

message = "Your email message has been received and you will receive a response shortly<br />Thank You for contacting TheApartmentGallery.com"

Author

Commented:
This is what I got after doing that.

Your email message has been received and you will receive a response shortlyThank You for contacting TheApartmentGallery.com

Commented:
I tested it out with both my suggestion and PaulHews one, here is the code I used and it worked 100% with both.
<%@ Import Namespace="System" %> 
<%@ Import Namespace="System.Web.Mail" %> 
 
<head>
<script type="VB" runat="server" > 
 
Private Function SendConfirmation()
 
	SmtpMail.SmtpServer = "your.mailserver.here"
 
	Dim message As String
	dim objMail as new MailMessage()
	message = "Your email message has been received and you will receive a response shortly" & VbCrLf & "Thank You for contacting TheApartmentGallery.com"
	objmail.to = "my@email.goes.here"
	objmail.from = "your@email.goes.here"
	objmail.subject = "Auto Response From the Apartment Gallery"
	objmail.body = message
 
	SmtpMail.Send(objmail)
 
End Function
 
Sub Page_Load(sender As Object, e As EventArgs)
	SendConfirmation()
End Sub
 
</script>
</head>

Open in new window

Author

Commented:
Thank you the vbcrlf statement is the one that works with the vb script.