I'm trying to make a quick and dirty c# asp.net webforms app. Nothing fancy.
new webforms project, open the designer for default.aspx.cs
Then drag a button and a textbox off the toolbar onto the page.
Then double-click on the button in the designer to get the click method and it's 100% reproducible. The app is literally as simple as you can get.
This may be a really basic issue, I suspect it's an update on another thread issue.
In my default.aspx.cs file, I'm hitting a webAPi, getting "OK" back. I want the text of the textbox1 to change from "?" to "OK" returned from the web service.
I click the button everything executes as expected, I see the text get changed in the debugger, but on the webpage it's still the old "?" value.
I'm guessing it's because I'm updating it in a response on a different thread?
protected void Button1_Click( object sender, EventArgs e )
{
try
{
// Create an HttpClient instance
HttpClient client = new HttpClient();
// Send a request asynchronously continue when complete
client.GetAsync( "http://localhost:44331/DoCdssLoginTests?sAdName=bob.bob" ).ContinueWith(
( requestTask ) =>
{
// Get HTTP response from completed task.
HttpResponseMessage response = requestTask.Result;
// Check that response was successful or throw exception
response.EnsureSuccessStatusCode();
// Read response asynchronously as JsonValue
response.Content.ReadAsStringAsync().ContinueWith(
( readTask ) =>
{
var result = readTask.Result;
//Do something with the result
TextBox1.Text = result.ToString();
Button1.Text = result.ToString();
} );
} );
}
catch ( Exception ex )
{
TextBox1.Text = ex.Message;
throw;
}
Can anyone see what I'm doing wrong? I tried updating the text on the button too, but it also looks like it got changed and is unaltered on the page refresh.