The topic describes how to post a form using ASP.Net generic handlers.
public class reqTpNb : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string formToSubmit = fnBuildForm("http://ahsaan-ansari@blogspot.com", strMsg);
context.Response.Write(formToSubmit);
}
public string fnBuildForm(string url,string data)
{
string formID = "PostForm";
//Build the form using the specified data to be posted.
System.Text.StringBuilder strForm = new System.Text.StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" + formID + "\" action=\"" + url + "\" method=\"POST\">");
strForm.Append("<input type=\"hidden\" name=\"msg\" value=\"" + data + "\">");
strForm.Append("</form>");
//Build the JavaScript which will do the Posting operation.
System.Text.StringBuilder strScript = new System.Text.StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." + formID + ";");
strScript.Append("v" + formID + ".method='post';");
strScript.Append("v" + formID + ".action='" + url + "';");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
//Return the form and the script concatenated.
//(The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
Enjoy happy coding....
public class reqTpNb : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string formToSubmit = fnBuildForm("http://ahsaan-ansari@blogspot.com", strMsg);
context.Response.Write(formToSubmit);
}
public string fnBuildForm(string url,string data)
{
string formID = "PostForm";
//Build the form using the specified data to be posted.
System.Text.StringBuilder strForm = new System.Text.StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" + formID + "\" action=\"" + url + "\" method=\"POST\">");
strForm.Append("<input type=\"hidden\" name=\"msg\" value=\"" + data + "\">");
strForm.Append("</form>");
//Build the JavaScript which will do the Posting operation.
System.Text.StringBuilder strScript = new System.Text.StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." + formID + ";");
strScript.Append("v" + formID + ".method='post';");
strScript.Append("v" + formID + ".action='" + url + "';");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
//Return the form and the script concatenated.
//(The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
Enjoy happy coding....
very usefull....
ReplyDeletethanks...a lot..
Delete