We help IT Professionals succeed at work.

ASP.net form processing page from Flash

pGustafson
pGustafson asked
on
Is it possible to send form data to a .net page without loading the page? The form data is coming from a flash movie.

If this is possible, what is the best way to do it. I have tried the following code and nothing happens.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Configuration;

public partial class player_roger_send_form : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

			string sOrgID, sPostData, sPostToURL, fname, lname, strTitle, strRole, strCompany, strCompanySize, strCountry, strEmail, strPhone, strPhoneExt, campaign, campaignid;

			sOrgID = "xxxx";
			campaign = "xxxxx";
			campaignid = "xxxxxx";
			sPostToURL = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
			// Fill variables with form data
			fname = Request.Form["First Name"];
			lname = Request.Form["Last Name"];
			strTitle = Request.Form["Title"];
			strRole = Request.Form["Role"];
			strCompany = Request.Form["Company"];
			strCompanySize = Request.Form["Company Size"];
			strCountry = Request.Form["COuntry"];
			strEmail = Request.Form["Email"];
			strPhone = Request.Form["Phone"];
			strPhoneExt = Request.Form["Phone Ext"];

			if (fname != null)
			{

				// Create string to send to SFDC
				sPostData = "&lead_source=Web" +
									 "&00N30000001FBQO=inquiry" +
									 "&00N30000001GFL5=" + campaign +
									 "&Campaign_ID=" + campaignid +
									 "&external=1" +
									 "&oid=" + sOrgID +
									 "&first_name=" + fname +
									 "&last_name=" + lname +
									 "&company=" + strCompany +
									 "&00N30000001FCNQ=" + strCompanySize +
									 "&00N30000001Gqqe=" + strRole +
									 "&title=" + strTitle +
									 "&00N30000001FpGY=" + strCountry +
									 "&email=" + strEmail +
									 "&00N60000001g2Z6= Filled out form after watching videos by xxxxx" +
									 "&phone=" + strPhone + "Ext:" + strPhoneExt +
									 "&00N60000001VNP1=http://www.xxx.com/player/xxxxxx/videoPlayer.html";



				// Send Data to SFDC
				sPostToURL = sPostToURL + sPostData;
				String myWebReturn = MakeWebRequest(sPostToURL, "");

				Response.Write("status=sent");
			}
    }

		protected string MakeWebRequest(string url, String webProxyServer)
		{
			string returnData = String.Empty;

			WebRequest request = WebRequest.Create(url);
			if (webProxyServer.Trim().Length > 0)
			{
				request.Proxy = GetWebProxy(webProxyServer);
			}
			HttpWebResponse response = (HttpWebResponse)request.GetResponse();

			if (response.StatusCode == System.Net.HttpStatusCode.OK)
			{
				Stream data = response.GetResponseStream();
				StreamReader reader = new StreamReader(data);
				returnData = reader.ReadToEnd();
			}
			else
			{
				Console.WriteLine("Error making WebRequest for url: " + url);
			}

			return returnData;
		}

		protected IWebProxy GetWebProxy(String webProxyServer)
		{
			string webProxyAddress = null;
			try
			{
				webProxyAddress = webProxyServer;
				if (webProxyAddress != null)
				{
					webProxyAddress = webProxyAddress.Trim();
					if (webProxyAddress == String.Empty)
					{
						webProxyAddress = null;
					}
				}
			}
			catch (Exception)
			{
				// Any exception ==> no proxy: the COM interop often throw an exception for the case of no proxy server!
				webProxyAddress = null;
			}

			//Initialize to no proxy
			//IWebProxy iwebProxy = GlobalProxySelection.GetEmptyWebProxy();
			IWebProxy webProxy = WebRequest.DefaultWebProxy;

			if (webProxyAddress != null)
			{
				webProxy = new WebProxy(webProxyAddress);
			}

			return webProxy;
		}
}

Open in new window

Comment
Watch Question

If you don;t want to process the page and pass data.
Then host the web service and complete the task

Author

Commented:
I am new to .net so I am not sure what you're talking about.
Check the link for creating web services
http://www.codeproject.com/KB/webservices/aspwebsvr.aspx

This might give u a idea

Author

Commented:
How would I rewrite my code to a web service? All one page, no separate code behind.