Web Page aspx issue - asp.net

I'm trying to access a the page below but I'm getting the following error:
Offending URL: http://www.mockcourt.org.uk/default.aspx
Source: App_Web_azvlqjha
Message: Object reference not set to an instance of an object. Stack
trace: at _Default.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Does anyone know what is causing this?
Thanks
Ross

Theres not enough information to say exactly, but at a guess there is an object being referenced in your Page_Load method which does not exist. Perhaps you have something like:
Page.FindControl("ID_Here")
Where there is no control with the ID: ID_HERE

Related

asp.net application while deploying in IIS7 server error - cannot find table 0

I tried deploying an ASP.NET application in IIS server 7. I am using Windows 7. While deploying i am getting the error "Cannot find table 0."
Exception Details: System.IndexOutOfRangeException: Cannot find table 0
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IndexOutOfRangeException: Cannot find table 0.]
System.Data.DataTableCollection.get_Item(Int32 index) +95
LHS.RightColumn.Page_Load(Object sender, EventArgs e) in C:\Saravanan\Saravanan\Saravanan\LHS\LHS\RightColumn.ascx.cs:33
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Please help me how to resolve this.
In Visual Studio this application is running fine.
But in IIS it is showing this error.
Please help me in this
I had this error some weeks back and it occurred because the web.config file was incorrect. The database information was invalid. Hopefully, this will help you.

ASP.NET: Random.Next: NullReferenceException?

I am trying to set the text of two labels to random numbers on page load. This code
Random random = new Random();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LINE 22 Label12.Text = random.Next(99).ToString();
LINE 23 Label13.Text = random.Next(999).ToString();
}
foreach (string s in scr1.Style.Keys)
{
Response.Write(s + ",");
}
}
...
works on localhost but when run on my server throws a NullReferenceException.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
.apps..Page_Load(Object sender, EventArgs e) in C:\Users**\Documents\Visual Studio 2010\Projects****\apps**.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Two options:
Label12 could be null
random could have been set to null by some other piece of code
The first part of diagnosing the problem would be to work out which of those is the case. Simply split the assignment:
string randomText = random.Next(99).ToString();
Label12.Text = randomText;
Then see which line it fails on. Once you know which expression is null, you can try to work out why it's null.

Run-time Error for adding attribute in html meta tag

Here is my code:
public partial class Image : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta tag = new HtmlMeta();
tag.Attributes.Add("property", "og:type");
Header.Controls.Add(tag);
}
}
This is my error:
Server Error in '/Kidzania' 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:
Line 18: HtmlMeta tag = new HtmlMeta();
Line 19: tag.Attributes.Add("property", "og:type");
Line 20: Header.Controls.Add(tag);
Source File: d:\Kidzania\Image.aspx.cs Line: 20
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.] Image.Page_Load(Object sender, EventArgs e) in
d:\Kidzania\Image.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+627
i am refer all stackoverflow answer but not solve that problem please any help to assisted me please. thanks in advance for your answers
This how I think it will work.
HtmlMeta htmmeta = new HtmlMeta();
htmmeta.Attributes.Add("property", "og:type");
this.Header.Controls.Add(htmmeta);
Also you need to make sure that in your mark up header tag has runat server.
<head runat="server">

Column '' does not belong to table " even though it is present in the table and the query

Error Message is :
Exception of type 'System.Web.HttpUnhandledException' was thrown.
Friendly Message : System.ArgumentException: Column 'testfile' does
not belong to table . at System.Data.DataRow.GetDataColumn(String
columnName) at System.Data.DataRow.get_Item(String columnName) at
Registration_test.FillImage() in
c:\inetpub\wwwroot\testWeb\Events\Registration.aspx.cs:line 49 at
Registration_test.Page_PreInit(Object sender, EventArgs e) in
c:\inetpub\wwwroot\testWeb\test\Registration.aspx.cs:line 39 at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Page.OnPreInit(EventArgs e) at
System.Web.UI.Page.PerformPreInit() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Target Site : Boolean HandleError(System.Exception) Source :System.Web
Error Stack Trace is : at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest() at
System.Web.UI.Page.ProcessRequest(HttpContext context) at
ASP.events_registration_aspx.ProcessRequest(HttpContext context) in
c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET
Files\testWeb\761ce6e4\d915dd85\App_Web_posk8hm6.6.cs:line 0 at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
I have got the above error as email when the site is hosted in IIS, but i donot get it when i am checking the code locally or even online.The error says the testfile column doesnot belong to datable even though the query returns the column.
can anyone help what could be the cause..
//////////////////////this is my code///////////////////////////////////////////////////
public partial class Registration_Registration : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
FillImage();
}
protected void FillImage()
{
string Query = "select t.header_image_file as 'HeaderImage',t.image,c.testfile from registrars c left join trade t on c.tradeid = t.tradeid and c.mainitemid = t.mainitemid ";
DataTable result = GetDataTable(Query);
if (result != null && result .Rows.Count > 0)
{
if (result .Rows[0]["testfile"] != null)
{
this.Theme = result .Rows[0]["testfile"].ToString().Trim();
this.MasterPageFile = result .Rows[0]["testfile"].ToString().ToLower().Trim() + ".master";
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}}
Ok so at a first glance we are seeing that the error is related to a column not being in a table.
To fix this I suggest you first run the query in management studio, check the names of the columns returned against the ones you are trying to access in your ASP.Net page.
If the column names are all correct backup the data then drop and recreate the table and the stored procedure that accesses this table and hopefully this will solve the issue.
It is a fairly easy to accidentally update a column etc in your database whilst developing and not push that change through to your production database.
If this doesnt solve things you will be able to get better help if you post your table structure, the query and the code which is accessing the query so we can diagnose the problem more efficiently.
UPDATE:
These are the columns you are selecting in your query
strt.header_image_file as 'HeaderImage',
t.image,
c.themefile
Yet in your code you are trying to access a column called testfile

how to use OutputCache in a userControl in asp.net

I have a aspx page that have this piece of code to load a usercontrol loaded from database
Control userControl = new Control();
userControl = LoadControl(userControlName);
((HiddenField)userControl.FindControl("HiddenFieldCategoryID")).Value = categoryID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldNewsID")).Value = newsID.ToString();
((HiddenField)userControl.FindControl("HiddenFieldTypeID")).Value = typeID.ToString();
PlaceHolder3.Controls.Add(userControl);
and the ascx have an outputcache
<%# OutputCache Duration=10 VaryByParam="none" %>
when i browse the page
this error comes out
[NullReferenceException: Object
reference not set to an instance of an
object.]
Content_SectionNews.Page_Load(Object
sender, EventArgs e) in c:\Documents
and Settings\Administrator\My
Documents\Visual Studio
2005\Projects\AnaweenNews.root\AnaweenNews\anaween
website\Content\SectionNews.aspx.cs:127
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr
fp, Object o, Object t, EventArgs e)
+14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs
e) +99
System.Web.UI.Control.LoadRecursive()
+50 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET
Framework Version:2.0.50727.3615;
ASP.NET Version:2.0.50727.3618
The type that returned from the LoadControl it will be PartialCachingControl, please follow the steps to how use the PartialCachingControl:
PartialCachingControl userControl = LoadControl(userControlName) as PartialCachingControl;
PlaceHolder3.Controls.Add(userControl);
if(userControl.CachedControl != null)
{
((HiddenField)userControl.CachedControl.FindControl("HiddenFieldCategoryID")).Value = categoryID.ToString();
((HiddenField)userControl.CachedControl.FindControl("HiddenFieldNewsID")).Value = newsID.ToString();
((HiddenField)userControl.CachedControl.FindControl("HiddenFieldTypeID")).Value = typeID.ToString();
}

Resources