8 Replies - 5563 Views - Last Post: 21 October 2009 - 08:48 AM Rate Topic: -----

#1 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

ASP.NET 3.0 / C# Contact Form

Post icon  Posted 19 October 2009 - 04:09 AM

Hello there. I am trying to develop a contact form in AS 3.0 / C#. I already have my AS 3.0 code but I do not know where to start in the C# code. I could've easily done it in PHP, but the guy I'm doing this project for insisted that it should be in ASP.NET. I do know basic C# and ASP.NET but I'm still in the early stages of my ASP.NET learning. So, I would really appreciate some here. I'm not sure if there's some POST method in C# but that's what I'm looking for because that's how I'll be sending the variables from AS 3.0... here's my code:

var variables:URLVariables = new URLVariables;
var varSend:URLRequest = new URLRequest("//ASP filename");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void {
	name_txt.text = "";
	email_txt.text = "";
	message_txt.text = "";
	phone_txt.text = "";
	company_txt.text = "";
	
	status_txt.text = event.target.data.return_msg;
}

submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

function ValidateAndSend (event:MouseEvent):void {
	
	if(!name_txt.length) {
		status_txt.text = "Please enter your name";
	} else if (!email_txt.length) {
		status_txt.text = "Please enter your email";
	} else if (!message_txt.length) {
		status_txt.text = "Please enter your message";
	} else {
		variables.userName = name_txt.text;
		variables.userEmail = email_txt.text;		
		variables.userMessage = message_txt.text;
		variables.userCompany = company_txt.text;
		variables.userPhone = phone_txt.text;
		
		varLoader.load(varSend);	
	}	 
}



Is This A Good Question/Topic? 0
  • +

Replies To: ASP.NET 3.0 / C# Contact Form

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6075
  • View blog
  • Posts: 23,540
  • Joined: 23-August 08

Re: ASP.NET 3.0 / C# Contact Form

Posted 19 October 2009 - 06:01 AM

I'm not sure what this is. I've never seen C# code like this before:
var variables:URLVariables = new URLVariables;
var varSend:URLRequest = new URLRequest("//ASP filename");

but I think this should go in ASP.NET.
Was This Post Helpful? 0
  • +
  • -

#3 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 19 October 2009 - 06:58 AM

No, this is not C# code. This is Actionscript 3.0! I already mentioned in my post that I have the AS3.0 code ready, but I do not even know where to start in C#... or maybe I should use use another language? but what I know is that the ASP.NET framework has different languages but they all end up being compiled to produce the same code...
Was This Post Helpful? 0
  • +
  • -

#4 W3bDev  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 379
  • Joined: 15-March 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 19 October 2009 - 09:49 AM

Okay, so you basically are doing just a basic asp.net form correct? You can use the built in validator to ensure an item has been entered.

<%@ Page Language="C#" %>
<script runat="server">

	void Button1_Click(Object sender, EventArgs e) {
	   Label1.Text = "Page is valid!";
	}

</script>
<html>
<head>
</head>
<body>
	<form runat="server">
		<p>
			<asp:TextBox id="TextBox1" 
			 runat="server"></asp:TextBox>
			&nbsp; 
			<asp:RequiredFieldValidator 
			 id="RequiredFieldValidator1" runat="server" 
			 ErrorMessage="Required!" 
			 ControlToValidate="TextBox1">
			</asp:RequiredFieldValidator>
		</p>
		<p>
			<asp:Button id="Button1" onclick="Button1_Click" 
			 runat="server" Text="Button"></asp:Button>
		</p>
		<p>
			<asp:Label id="Label1" runat="server"></asp:Label>
		</p>
	</form>
</body>
</html>




Complete documentation: http://msdn.microsof...y/aa479013.aspx

Where to go from here really depends on what you want to do with the data, you can email it, or you can post it to a database... the choice is yours.

This post has been edited by W3bDev: 19 October 2009 - 09:50 AM

Was This Post Helpful? 0
  • +
  • -

#5 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 20 October 2009 - 02:34 AM

No, I don't think that's what I'm looking for... I simply want to receive variables that are "POSTED" from Flash Actionscript 3.0, and then use those variables after converting them into local ASP.NET vars, to send a message to some email address of my choosing.

I found the following code on some website but I don't think it's in C#... maybe I should've posted this thread in the ASP.NET forum or something but anyway here's the code... I want something similar:

<%
dim Nm,Comments
Nm=request("t1")
Comments=request("t2")
Set objCDONTS = server.CreateObject("CDONTS.NewMail")
With objCDONTS
. From = "webenquiry@example.com"
. to = "admin@example.com" 
.Subject = "Website enquiry"
.Body = Nm & "<br>" & Comments
.BodyFormat = 0 ' CdoBodyFormatHTML
.Send
Set objCDONTS = Nothing 
%> 


Was This Post Helpful? 0
  • +
  • -

#6 W3bDev  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 379
  • Joined: 15-March 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 20 October 2009 - 10:05 AM

 
// in declaration
using System.Web.Mail;

create a button on page name
// in page class
protected void Page_Load(object sender, EventArgs e)
{
MailMessage objEmail = new MailMessage();
objEmail.To = "YOUREMAILHERE";
objEmail.From = "WHOSENTFROM";
objEmail.Subject = "EMAILSUBJECT";
objEmail.Body = "New Email REcieved... bla bla bla <br /> <br />";
objEmail.Body += request.Form("IncomingVariable");

// you can add as much to the body as you want

// if you want the email formatted in HTML, add this line
objEmail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "relay-hosting"; // most hosting providers have a secure relay to send email from your server
// example: SmtpMail.SmtpServer = "relay-hosting.secureserver.net"; (godaddy)

SmtpMail.Send(objEmail);

Response.Redirect("mailsent.html");

}


This post has been edited by W3bDev: 20 October 2009 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#7 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 20 October 2009 - 11:03 AM

oh this code is great! almost does what I'm looking for! There's just one thing that is still missing... I want to retrieve variables that are posted from my SWF. I am using the post method to send the variables to the .cs page. I hope you understand what I'm trying to accomplish here. It's like rather than getting variables posted by an HTML form and using them in your ASP form, I'll be getting the variables from Flash. The concept is the same, I just want to know how to get those variables. I'll provide a PHP version of what I'm looking for, hopefully you also know PHP because I'm sure it'll clear things out... here's the code:

<?php
// Create local variables from the Flash ActionScript posted variables
$senderName	 = stripslashes($_POST['userName']);
$senderEmail	 = stripslashes($_POST['userEmail']);
$senderMessage	 = stripslashes($_POST['userMessage']);
$senderPhone	 = stripslashes($_POST['userPhone']);
$senderCompany	 = stripslashes($_POST['userCompany']);

// IMPORTANT - Change these lines to be appropriate for your needs - IMPORTANT !!!!!!!!!!!!!!!!!!
$to		 = "kassem.darwish@live.com";			 
$from		 = "$senderEmail";
$subject	 = "Message from $senderName";

// Modify the Body of the message however you like
$message	 = "Results from the form:

Name: $senderName 
Email: $senderEmail
Company: $senderCompany
Phone: $senderPhone

Their Message is below: 

$senderMessage";


// Build $headers Variable
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n"; 

// Send the email
mail($to, $subject, $message, $headers);

// Assemble the message that goes back to Flash
// The flash ActionScript is looking for a return variable of "return_msg"
$my_msg = "Thanks $senderName, all data has been sent.";
// Print the data back to flash who is patiently waiting for it in the onCompleteHandler
print "return_msg=$my_msg"; 
?>



thanks for the help anyway, I really appreciate it :)
Was This Post Helpful? 0
  • +
  • -

#8 W3bDev  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 42
  • View blog
  • Posts: 379
  • Joined: 15-March 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 20 October 2009 - 12:05 PM

Try:
Request.Params.Get(”userName").ToString();

Was This Post Helpful? 0
  • +
  • -

#9 Striker9099  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 19-October 09

Re: ASP.NET 3.0 / C# Contact Form

Posted 21 October 2009 - 08:48 AM

Are you sure it is Request.Params.Get? I repeat, I'm sending the variables using the POST method, but I cannot be sure if that's the right way to do it so I'll just go by your advice...

Here's what I came up with, please tell me if there's something missing or wrong...

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

using System.Web.Mail;

String senderName = Request.Params.Get(”userName").ToString();
String senderEmai = Request.Params.Get(”userEmail").ToString();
String senderMessage = Request.Params.Get(”userMessage").ToString();
String senderPhone = Request.Params.Get("userPhone").ToString();
String senderCompany = Request.Params.Get("userCompany").ToString();

protected void Page_Load(object sender, EventArgs e)
{
MailMessage objEmail = new MailMessage();
objEmail.To = "kassem.darwish@live.com";
objEmail.From = senderName + "(" + senderEmail + ")";
objEmail.Body = "New Email Recieved... <br /> <br />";
objEmail.Body += "Name: " + senderName;
objEmail.Body += "Phone: " + senderPhone;
objEmail.Body += "Company: " + senderCompany;
objEmail.Body += "Message: " + senderMessage;


objEmail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "relay-hosting"; 

SmtpMail.Send(objEmail);

}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1