Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpContext.Current is null when in method called from PageAsyncTask
    primarykey
    data
    text
    <p>I have a scenario where i have a page which opens a dialog on click of a button, in the opened dialog form on button click i can read a list of data from a selected .txt file and build a query and add the data to some database tables. Since there could be large amount of data this process can take large time because of this the user would not be able to work on the application until the upload completes. Hence to make the upload process Asynk i am using the PageAsyncTask. Below is the code sample, but in the method called in the PageAsyncTask the HttpContext.Current is null hence i am not able to use session handling. Please any guidance on this why would this be null and how can i use the session in this case</p> <pre><code> protected void BtnUpload_click(object sender, EventArgs e) { PageAsyncTask asyncTask1 = new PageAsyncTask(OnBegin, OnEnd, OnTimeout, SessionManager.UserData, true); Page.RegisterAsyncTask(asyncTask1); Page.ExecuteRegisteredAsyncTasks(); } public IAsyncResult OnBegin(object sender, EventArgs e, AsyncCallback cb, object extraData) { _taskprogress = "AsyncTask started at: " + DateTime.Now + ". "; uData = extraData as UserData; _dlgt = new AsyncTaskDelegate(BeginInvokeUpload); IAsyncResult result = _dlgt.BeginInvoke(cb, extraData); return result; } private void BeginInvokeUpload() { string selectedFileName = string.Empty; string returnValuePage = string.Empty; User teller = new User(); SessionManager.UserData = uData; } private void BeginInvokeUpload() { string selectedFileName = string.Empty; string returnValuePage = string.Empty; User teller = new User(); SessionManager.UserData = uData; } public class SessionManager { public static UserData UserData { get { UserData userData = null; if (HttpContext.Current.Session["UserData"] != null) { userData = HttpContext.Current.Session["UserData"] as UserData; } return userData; } set { HttpContext.Current.Session["UserData"]=value; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload