Reputation: 85
I have a button on click action, how can I add a error catch and return a textbox if result is not found. If result is found the textbox will be searched results. I have the following codes.
var response = e.Result.getSearchCoordsResult;
var pagedResults = JsonConvert.DeserializeObject<TestMap.Classes.Global.ResultSetPager<TestMap.Classes.Global.Place>>(response);
Classes.Global.searched = 1;
Results.ItemsSource = pagedResults.SearchResults;
if (!e.Result.ToString().Equals("error"))
{
searchError.Text = "No Results Found";
}
else
{
searchError.Text = "Search Result";
}
This code wont work, it just cause the system to crash.
Upvotes: 0
Views: 169
Reputation: 2461
Have you tried a try catch?
try
{
var response = e.Result.getSearchCoordsResult;
var pagedResults = JsonConvert.DeserializeObject<TestMap.Classes.Global.ResultSetPager<TestMap.Classes.Global.Place>>(response);
Classes.Global.searched = 1;
Results.ItemsSource = pagedResults.SearchResults;
searchError.Text = "Search Result";
}
catch (Exception ex)
{
searchError.Text = "No Results Found";
}
Upvotes: 1