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();
}
Related
[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.First(IEnumerable`1 source) +269
umbraco.cms.businesslogic.packager.Installer.InstallBusinessLogic(Int32 packageId, String tempDir) +2226
umbraco.presentation.developer.packages.Installer.ProcessInstall(String currentStep) +228
umbraco.presentation.developer.packages.Installer.Page_Load(Object sender, EventArgs e) +423
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
umbraco.BasePages.BasePage.OnLoad(EventArgs e) +14
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
I have installed fresh from application gallery and tried to install package from cms admin. And i am getting this error. How to resolve this error.
I think that this module, Business Website Starter Pack is not compatible with Umbraco 7. The Last update was 4 years ago.
I am getting the following error:
Specified cast is not valid.
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.InvalidCastException: Specified cast is not valid.
Code:
<asp:RadioButtonList ID="rbtVerified" runat="server" Visible='<%#!(bool)Eval("ReadOnly") %>' >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
Value ReadOnly is being retrieved successfully from the database and it is bool (saved as bit in sql server. What exactly could the problem be?
Exception is also being thrown here when trying to bind the data (Note: bool testis just a test to check if variable ReadOnly being retrieved properly from the database.
DataTable dt = new LeaveLogic().GetManagerUnverifiedLeaveRequests(Convert.ToInt32(Context.User.Identity.Name));
if (dt.Rows.Count > 0)
{
bool test = Convert.ToBoolean(dt.Rows[0]["ReadOnly"]);
RptLeaveRequests.DataSource = dt;
RptLeaveRequests.DataBind();
}
More detaield error:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Specified cast is not valid.
Source=App_Web_kdnthep4
StackTrace:
at ASP.webpages_verifyleaverequests_aspx.__DataBinding__control43(Object sender, EventArgs e) in c:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx:line 35
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.BindData() in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 58
at _1.PresentationLayer.WebPages.VerifyLeaveRequests.Page_Load(Object sender, EventArgs e) in C:\Users\Samsung\Desktop\Development\Ticketing system\1.PresentationLayer\WebPages\VerifyLeaveRequests.aspx.cs:line 24
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)
InnerException:
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.
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">
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