473,289 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Specified cast is not valid

1
Thank for your answer. :-)
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.

Source Error:


Line 271: Microsoft.Web.UI.WebControls.TreeNode iNode = null;
Line 272:
Line 273: iNode = (Microsoft.Web.UI.WebControls.TreeNode) N;
Line 274:
Line 275: foreach ( Microsoft.Web.UI.WebControls.TreeNode tempNode in iNode.Nodes )


Source File: c:\inetpub\wwwroot\payroll_cs\frmmenu.aspx.cs Line: 273

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
Payroll_CS.frmMenu.CheckEmptyNode(Object N) in c:\inetpub\wwwroot\payroll_cs\frmmenu.aspx.cs:273
Payroll_CS.frmMenu.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\payroll_cs\frmmenu.aspx.cs:106
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
Expand|Select|Wrap|Line Numbers
  1. call CheckEmptyNode (treeview)
  2.  
  3.  
  4. public void CheckEmptyNode( Object N ) 
  5.         {             
  6.             Microsoft.Web.UI.WebControls.TreeNode menuNode = null; 
  7.             Microsoft.Web.UI.WebControls.TreeNode iNode = null;
  8.  
  9.             iNode = (Microsoft.Web.UI.WebControls.TreeNode) N;
  10.  
  11.             foreach ( Microsoft.Web.UI.WebControls.TreeNode tempNode in iNode.Nodes ) 
  12.             { 
  13.                 menuNode = tempNode;                
  14.                 if ( menuNode.Nodes.Count > 0 ) 
  15.                 { 
  16.                     CheckEmptyNode( menuNode ); 
  17.                 } 
  18.                 else 
  19.                 { 
  20.                     if ( menuNode.NavigateUrl.Trim() == "" ) 
  21.                     {                         
  22.                         itemNode.Nodes.Remove( menuNode ); 
  23.  
  24.                         if ( itemNode.Nodes.Count > 0 ) 
  25.                         { 
  26.                             CheckEmptyNode( N ); 
  27.                         }                         
  28.                         return;                         
  29.                     }                     
  30.                 }                 
  31.             }            
  32.         }
  33.  
May 20 '09 #1
2 8711
Curtis Rutland
3,256 Expert 2GB
From a quick glance, I'd say that you're passing an Object to your method that can't be cast as a Microsoft.Web.UI.WebControls.TreeNode.

That's the only cast you're doing, and the error message says "invalid cast."
May 20 '09 #2
Plater
7,872 Expert 4TB
Indeed, N is not a Microsoft.Web.UI.WebControls.TreeNode nor a class that derives from Microsoft.Web.UI.WebControls.TreeNode.

OR Whats contained in N.Nodes is not garunteed to be reducable to a Microsoft.Web.UI.WebControls.TreeNode
May 21 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.