I have a search control, when the user clicking on search the query is passing in the url (get mode) with the following line from the code behind:
Server.Transfer("portfolio_search_results.aspx?search=" + query);
now i have a very strange problem, if the user is clicking on the search button the search works fine, but if the user click search again the error
Object reference not set to an instance of an object.
is raising. going to other page after the search and searching again works fine, this is happening only when clicking search button twice in a row.
the search control is in the top of the page inside the master.
the code in the search function:
SqlCommand cmd = new SqlCommand("something", _mainConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("ID", SessionManager.Session[SessionParam.ID].ToString()));
cmd.Parameters.Add(new SqlParameter("Type", type));
return _mainDb.ExecuteDataSet(cmd).Tables[0];
and the error is in the session.
If i am using Response.Redirect instead of Server.Transfer it’s not working at all and getting the above error even in the first time searching.
edit: adding stack trace.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.0.cs Line: 0
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Appeals.GetAppeals(String typeAppeals) +104
search.make_dt() +21
search..ctor() +311
portfolio_search_results..ctor() +26
ASP.portfolio_search_results_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.0.cs:0
__ASP.FastObjectFactory_app_web_portfolio_search_results_aspx_cdcab7d2_jiztmxz2.Create_ASP_portfolio_search_results_aspx() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.1.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:2.0.50727.3634; ASP.NET Version:2.0.50727.3634
I solve it by passing the session as parameter to my classes in App_code directory in my project instead using the session parameter inside the App_code classes.
so the study is that session wouln’t be use in the app_code directory .