I am building an ASP.NET web application that loads data dynamically from a MySQL database. I already know that I can change the properties of client control from within an event on the server that is triggered by another client control (a button click, for example).
That said, I have been unable to change the controls in that same fashion after downloading my dynamic data from the database. I think this is because the client has already been rendered by the time my data has finished downloading. Is there any way to inform the client that it should reload the page to receive the freshly downloaded data? Maybe I can send the data directly to the client?
In a perfect world, the dynamic data would start downloading in Page_Load, like below, and automatically populate the control (a DropDown in this case) once the data has been received and formatted (at the end of DownloadSchoolsInfo). Is this possible?
Thanks for any suggestions!
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Task task = new Task(DownloadSchoolsInfo);
task.Start();
}
}
async void DownloadSchoolsInfo()
{
Task<string> task = StaticData.DoStringDownload("http://php.domain.com/php/getAllSchoolInfos.php");
string s = await task;
string[] schoolData = s.Split('
');
foreach (string line in schoolData)
{
string[] sArray = line.Split(';');
StaticData.schools.Add(new SchoolInfo(sArray[0], sArray[1], sArray[2], sArray[3]));
}
dropDown_SchoolSelect.DataTextField = "name";
dropDown_SchoolSelect.DataValueField = "code";
dropDown_SchoolSelect.DataSource = StaticData.schools;
dropDown_SchoolSelect.DataBind();
}
public static async Task<string> DoStringDownload(string url)
{
var httpClient = new HttpClient();
string s = await httpClient.GetStringAsync(url);
return s;
}