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:
Related
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.
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
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();
}
Alright so I changed the column that the As of Sales column gets its data from, however they are both the exact same type and look the exact same, but i still get this error.Both are Decimal(38,6)
Input string was not in a correct format.
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.FormatException: Input string was not in a correct format.
Source Error:
Line 60: <asp:TemplateField HeaderText="As Of Sales">
Line 61: <ItemTemplate>
Line 62: <%#Getsales(Decimal.Parse(Eval("AsOFSales").ToString())).ToString("C0")%>
Line 63: </ItemTemplate>
Line 64: <FooterTemplate>
Source File: C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx Line: 62
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7471479
System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt) +146
System.Decimal.Parse(String s) +25
ASP.default2_aspx.__DataBind__control17(Object sender, EventArgs e) in C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx:62
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +211
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
System.Web.UI.Control.DataBind() +15
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
Default2.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\ChrisH\Desktop\AJAXEnabledWebSite4\Default2.aspx.vb:106
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
"SELECT dbo.bSaleAsOfAdvancedMaster.SDESCR, dbo.bSaleAsOfAdvancedMaster.DYYYY, dbo.bSaleAsOfAdvancedMaster.AsOFNET, dbo.bSaleAsOfAdvancedMaster.ASOFPAX, dbo.bSaleAsOfAdvancedMaster.YENET, dbo.bSaleAsOfAdvancedMaster.YEPAX, dbo.b1SalesAsOfAdvanced.netSales, dbo.b1SalesAsOfAdvanced.PAX AS CurrentPAX FROM b1SalesAsOfAdvanced INNER JOIN bSaleAsOfAdvancedMaster ON dbo.bSaleAsOfAdvancedMaster.SDESCR = b1SalesAsOfAdvanced.SDESCR WHERE (bSaleAsOfAdvancedMaster.DYYYY =" & DropDownList1.SelectedValue & ") AND (b1SalesAsOfAdvanced.DYYYY = (year( getdate() ))) order by bSaleAsOfAdvancedMaster.SDESCR"
Check that you don't have any NULL values coming through. This might be causing the problem.
EDIT
Added in here as well, easier to read:
<%#Getsales(String.IsNullOrEmpty(Eval("AsOfSales").ToString()) ? 0 : Decimal.Parse(Eval("AsOFSales").ToString())).ToString("C0")%>
Check what are distinct values returned for "AsOfSales" column by the query. May be there is a value tht doesn't fall into numeric format.
I have this problem :
[InvalidOperationException: No data exists for the row / column.]
System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal) +1029063
System.Data.OleDb.OleDbDataReader.GetInt32(Int32 ordinal) +12
ASP.addsousvoyage_aspx.hdVoyage_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\ZiGi\Desktop\VisualDesign\addSousVoyage.aspx:222
System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +111
System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +134
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +10
System.Web.UI.Page.RaiseChangedEvents() +165
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485
When I do this :
MsgBox(myReader1.GetInt32(0).ToString)
Even if :
MsgBox(myReader1.FieldCount) returning 1 as value and the field(0) is integer.
What's the problem ?
Have you forgotten to do a myReader1.Read()?
I think this error can occur when it's forgotten.