Saturday, October 5, 2013

Web Client :: Asynchronous operations are not allowed in this context. asp net

Add the Async="true" parameter to the @Page directive. like this

<%@ Page Async="true" AsyncTimeout="3000" ......

How to call API URL in asp.net c#

string url = "{url}"
string param = "name value pair data";
System.Net.WebClient webClient = new System.Net.WebClient();
string encoding = "application/x-www-form-urlencoded";
webClient.Headers[System.Net.HttpRequestHeader.ContentType] = encoding;
string res = webClient.UploadString(url, param);

How do I return a value to a sqldatareader if value is null? asp net c#

int CountryId;
SqlDataReader reader = ...........
 
if (reader.HasRows)
{
 reader.Read();
 CountryId = reader.GetInt16(reader.GetOrdinal("CountryId"));
 
But if CountryId is null it will throw an exception so use safe method

CountryId = !string.IsNullOrWhiteSpace(reader["CountryId"].ToString()) ? 
Convert.ToInt32(reader["CountryId"]) : -1; 

That is it