Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.

 Hello,

         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.
 

...
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
            <asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                    <asp:SiteMapPath ID="SiteMapPath1" runat="server">
                    </asp:SiteMapPath>
            </LayoutTemplate>
            <ItemTemplate>       
                <div>
                        ...
                </div>           
            </ItemTemplate>
            </asp:ListView>  

    Protected Sub SiteMapPath1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim siteMapControl As SiteMap = CType(ListView1.FindControl("SiteMapPath1"), SiteMap)

        ...
    End Sub
...


 

cheers,
imperialx 

0
imperialx
12/22/2007 8:05:56 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

4 Replies
1151 Views

Similar Articles

[PageSpeed] 43

It's a SiteMapPath, not a SiteMap 

Dim siteMapControl As SiteMapPath = CType(ListView1.FindControl("SiteMapPath1"), SiteMapPath)

or

Dim siteMapControl As SiteMapPath = CType(sender, SiteMapPath)


-- "Mark As Answer" if my reply helped you --
0
gunteman
12/22/2007 2:22:04 PM

 Hi gunteman,

                    Why does I receive this error "Object reference not set to an instance of an object."

...

   Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim lit As LinkButton = CType(SiteMapPath1.FindControl("LinkButton3"), LinkButton)
        lit.Visible = False
    End Sub

        <div class="breadcrumbs">
            <asp:SiteMapPath ID="SiteMapPath1" runat="server">
                <CurrentNodeTemplate>
                    <asp:LinkButton ID="LinkButton3" runat="server">LinkButton</asp:LinkButton>
                </CurrentNodeTemplate>
            </asp:SiteMapPath>           
        </div>
       
        <asp:ListView ID="itemListTutorial" runat="server">
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
            </LayoutTemplate>
            <ItemTemplate>
            ...
            </ItemTemplate>
        </asp:ListView>
    </div>

...
 

 
cheers,
imperialx 

0
imperialx
12/23/2007 4:54:18 AM

Hi,

Because the LinkButton3 is in the sitemappath control's itemtemplate, you should use the LinkButton3's clientID find the LinkButton3 control.,

For example:

  1. Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
  2.    
  3.     Dim lbtn As LinkButton = DirectCast(Me.Page.FindControl("SiteMapPath2$ctl00$LinkButton3"), LinkButton)
  4.     lbtn.Visible = False
  5. End Sub

Hope it helps.


Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Amanda
12/24/2007 8:49:56 AM

 A bit awkward I'd say.Setting properties in ItemDataBound would be easier.

I just wonder why you're creating a LinkButton, just to set it to invisible.


-- "Mark As Answer" if my reply helped you --
0
gunteman
12/24/2007 10:15:23 AM
Reply:

Similar Artilces:

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

BC30311: Value of type 'Control' cannot be converted to 'System.Web.UI.WebControls.CheckBox'
 Hi, can somebody help me on this problem. It works at first, but all of a sudden, it fails, and I can't find out why.    1 Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) 2 3 If Not CheckRequiredField() Then 4 MessageBox("Please complete the input data!") 5 Exit Sub 6 End If 7 8 Dim nRow As Integer 9 Dim Ctrl As Control 10 Dim chkDelete As Object 11 Dim LookupID, Name, Desc, Type As String 12 13 nRow = 0 14 1...

Cannot convert type 'System.Web.UI.Control' to 'FileUpload'
Hi,I'm getting an error in the follow code:FileUpload fileUpload1 = (FileUpload)itemPanel.FindControl("fuDoc");Where itemPanel is a AjaxControlToolkit.TabPanel and the aspx code is: <asp:FileUpload ID="fuDocument_es" runat="server" />The error is Cannot convert type 'System.Web.UI.Control' to 'FileUpload' Why? Thanks You are trying to find and convert "fuDoc" or "fuDocument_es"  ?try thisFileUpload fileUpload1 = (FileUpload)itemPanel.FindControl("fuDocument_es");...

Compiler Error Message: BC30311: Value of type 'System.Web.UI.Control' cannot be converted to 'IWizardStep'.
I am working with a Book ASPNET 2.0 Unleashed "by the way, great book". There code is witten with <script> tags and the vb is in the same page as the Html. So, as practice, I am simply trying to convert it to code behind... The page calls a class named "IWizardSetp" See both there code and my convered code below. I get the following error. What am I doing wrong? Details please if you can help... Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details a...

Error Serializing Value 'System.Web.UI.WebCOntrols.TreeNode' of type 'System.Web.UI.WebCOntrols.TreeNode'
Hi, I am  getting the error stated in the subject when i am storing a TreeNode in a ViewState and then using it as follows if (ViewState["ProductCounty"]!=null) { TreeNode _productCountyNode = DataTree.FindNode(((TreeNode)ViewState["ProductCounty"]).ValuePath); _productCountyNode.Expand(); } what could be causing this error? Hi, I believe TreeNode isn't serializable in a way its required for objects which can be put to ViewState - as reference - (TreeNode implements IStateManager and is meant to work together with TreeView itself saving it...

Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Hi, I'm getting this error when trying to port an old Atlas Web App to use the latest bits - any help would be nice as to what controls I CAN extend - so if I can't use a DIV what then?: Server Error in '/GRintranets' Application. Extender control 'DragPanelExtender1' cannot extend 'divPaginaHTML'. Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informati...

cannot convert from 'archive_class' to 'System.Web.UI.Control' ??
 i created this class and it takes 2 parameters and then i call that class and pass the parameters and add it to a palceholder control it should create a div tag and add an id and text in it .public archive_class(string DivID,string sText) {HtmlGenericControl div1 = new HtmlGenericControl("div"); div1.InnerText = sText; div1.ID = DivID;return; }   and i call the object here  protected void Page_Load(object sender, EventArgs e) {archive_class arch = new archive_class("someID","someText"); PlaceHolder1.Controls.Add(arch); }   ...

'System.Web.UI.Control' cannot be converted to 'String'.
I am trying to run a simple Edit, Update, Delete. I found a simple example in a book I've got. My only concern is withing the string it's first Declaration is Read only, so it won't be edited. and for some reason I am getting this error: The update function that is right after the page_load is giving me the problems. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30311: Value of type 'Sy...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'
Hello, Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated.  Using the code below I receive the error message above.  Please tell me what am I doing wrong? Do I need to cast the text as a literal?  Please help? Thank you in advance, <%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR"...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Hi, any idea why I'm getting the following error?Line 45: protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) Line 46: { Line 47: TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; Line 48: int Quantity = Convert.ToInt32(QuantityTextBox.Text); Line 49: Are you sure that the control at CartGrid.Rows[e.RowIndex].Cells[2].Controls[0] isn't a LiteralControl?  How are you creating code this in your code?Brent JenkinsASP.NET, C#, Web Developerwww.valewebdesign.co.uk  ...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid"...

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

Error 1 The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\asse
Once I build project. I encounter this error. Does someone experience this error?Error    1    The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.6.0.0__31bf3856ad364e35\System.Web.Extensions.dll'    D:\Source Code\Linq_Lesson5\Default.aspx    1    1    D:\Source Code\Linq_Lesson5\  It appears tha...

Web resources about - Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'. - asp.net.navigation-controls

Resources last updated: 1/14/2016 1:36:58 PM