I've got a Class in C# that is firing on a button click. When the button is clicked it fires CreateRepo()
protected void Button1_Click(object sender, EventArgs e)
{
//await MyClient.CreateRepo();
string Repo = TextBox2.Text;
var WebTask = MyClient.CreateRepo(Repo);
}
}
This is CreateRepo()
public class MyClient
{
public static TextBox TextBox2;
public static Button Button1;
public static Label Label1;
static async public Task<string> CreateRepo(string Repo1)
{
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.github.com/user/repos"))
{
var UserAgent1 = new ProductInfoHeaderValue("Bot", "1.0");
//Get Github Personal Access Token from Azure Key Vault
var kvsecret = ConfigurationManager.AppSettings["secret"];
//Use Github Personal Access Token from Azure Key Vault
request.Headers.TryAddWithoutValidation("Authorization", $"token {kvsecret}");
request.Headers.UserAgent.Add(UserAgent1);
request.Content = new StringContent($"{{\"name\":\"{Repo1}\"}}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
var http = response.StatusCode;
string stringhttp = http.ToString();
MyClient.Label1.Text = stringhttp;
HttpresponseFunction(stringhttp);
return stringhttp;
}
}
}
I'm just trying to pass the http response code inside stringhttp to populate Label1.text but it's just not working.
If I add it into the Button1 click as follows it seems to work:
protected void Button1_Click(object sender, EventArgs e)
{
//await MyClient.CreateRepo();
string Repo = TextBox2.Text;
var WebTask = MyClient.CreateRepo(Repo);
MyClient.label1.text = "hello world"
Inside my class I've added in the required objects to that the class can 'see' the controls as follows:
public static TextBox TextBox2;
public static Button Button1;
public static Label Label1;
..And I've converted the http Status code into a string
Is there a way I can write the value of stringhttp to the label