Note that there are some explanatory texts on larger screens.

plurals
  1. POChange Form label in static void GetResponseCallback
    primarykey
    data
    text
    <p>Hi I try to change label element but text not changing.</p> <pre><code> public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { sendPOST("http://example"); } public static void sendPOST(string URL) { // Create a request using a URL that can receive a post. HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the Method property of the request to POST. request.Method = "POST"; // start the asynchronous operation request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),request); allDone.WaitOne(); } private static void GetRequestStreamCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation Stream postStream = request.EndGetRequestStream(asynchronousResult); // Convert the string into a byte array. byte[] byteArray = Encoding.UTF8.GetBytes(""); // Write to the request stream. postStream.Write(byteArray, 0, postData.Length); postStream.Close(); // Start the asynchronous operation to get the response request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); } private static void GetResponseCallback(IAsyncResult asynchronousResult) { //..... Form1 test = new Form1(); test.statusLabel.Text = responseString; //dont write anything Console.WriteLine(responseString); //works well //..... } </code></pre> <p>How can I change it?</p> <p><strong>UPDATE: Add more code</strong>. How can I obtain existing Form1 instance to update Form1 LabelField to show something after asyn is done?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload