ikathegreat
ikathegreat

Reputation: 2321

output clipboard to multiple textboxes

I am trying to program a WinForms application to transfer textbox information from the application to a webpage. I would like to know if there is a way I can capture say 4 textbox's worth of text and be able to paste that into 4 corresponding textboxes on a webpage.

They will have the same arrangement/alignment. The reason for this is my data is being managed through a SQL database, the textboxes will display the related info and I need a better method to transfer the data rather than copy, paste, repeat.

Upvotes: 0

Views: 403

Answers (1)

payo
payo

Reputation: 4561

You can take advantage of HttpWebRequest, and set a string for each textbox:

var response = SendNamedStrings("http://example.com", new Dictionary<string,string>{
  { "textBox1", textBox1.Text },
  { "textBox2", textBox2.Text },
  { "textBox3", textBox3.Text },
  { "textBox4", textBox4.Text } 
} );

Where SendNamedStrings could be something like

static WebResponse SendNamedStrings(string url, Dictionary<string, string> namedStrings)
{
  string postData = "?" + string.Join("&", namedStrings.Select(pair => string.Format("{0}={1}", pair.Key, pair.Value)));

  WebRequest request = WebRequest.Create(url);
  request.Method = "POST";
  byte[] byteArray = Encoding.UTF8.GetBytes(postData);

  request.ContentType = "application/x-www-form-urlencoded";
  request.ContentLength = byteArray.Length;
  Stream dataStream = request.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();

  return request.GetResponse();
}

Note that this question has been asked in many ways before on stack overflow (here are just a few):

sending data using HttpWebRequest with a login page

How to add parameters into a WebRequest?

Sending POST data with C#

Upvotes: 2

Related Questions