- Mesajlar
- 1,726
Asp.Net te Respose.Redirect ile rahatlıkla QueryStringleri hedef url ye rahatlıkla gönderebiliyoruz. Ancak form u post methodu ile actiondaki bağlantıya gönderebilmek için harici bir sınıf (Class) tanımlamalıyız.
RemotePost.cs
RemotePost.cs
Kod:
using System;
using System.Collections.Generic;
using System.Web;
/// <summary>
/// Summary description for RemotePost
/// </summary>
public class RemotePost
{
private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name, string value)
{
Inputs.Add(name, value);
}
public void Post()
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html><head>");
System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.getElementsByTagName('form')[0].submit();\">", FormName));
System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\">", FormName, Method, Url));
for (int i = 0; i < Inputs.Keys.Count; i++)
{
System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
}
System.Web.HttpContext.Current.Response.Write("</form>");
System.Web.HttpContext.Current.Response.Write("</body></html>");
System.Web.HttpContext.Current.Response.End();
}
}
protected void sa_Click(object sender, EventArgs e)
{
RemotePost myremotepost = new RemotePost();
myremotepost.Url = "http://www.google.com.tr/cse";
myremotepost.FormName = "cse-search-box";
myremotepost.Add("cx", "partner-pub-3063188009093932:1rn1gw-8b24");
myremotepost.Add("ie", "utf-8");
myremotepost.Add("q", q.Text);
myremotepost.Post() ;
}