Solved

Cannot convert type 'System.Web.UI.MasterPage

Posted on 2008-10-27
6
1,393 Views
Last Modified: 2011-10-19
Please suggest some info to help me solve this compiler message.

Please view code snippit in screen image in the Uploaded files section. Thank you.

Cannot convert type 'System.Web.UI.MasterPage' to 'Perpetual_Inventory.MasterPage'      C:\Documents and Settings\dgish\Desktop\Perpetual Inventory\Perpetual Inventory\Home.aspx.designer.cs


masterpage.bmp
0
Comment
Question by:reed1989a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22815623
Seems you are trying to convert object of type Master into your custom type

try to return MasterPage in the function instead of perpetual_inventory.MasterPage
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22815691
What you have to do is caste the master page properly. The variable you use for storing the reference of your master page must be of the same type (i.e. type of your master page class)

Assuming my master page is MyMaster in MyNamespace, so from a content page, I would use code like one shown below to access my master page:

'Code in content pane

MyNamespace.MyMaster objMasterInstance = (MyNamespace.MyMaster) Page.Master;
return objMasterInstance //Now you are returning the correct master page. You should not just return the microsoft's System.Web.UI.MasterPage class instead must return your own class variable's instance like the one I have shown.
0
 

Author Comment

by:reed1989a
ID: 22816148
techExtreme:
Thank you for reviewing this soluion
 I have interpreted what you said to do is make a property in the code behind of the master page that must return the correct master page.
Please see if the code below is correct.

public Prepetual_Inventory.MasterPage menuMasterPage 
	{
 
		 
        get
        {
            Prepetual_Inventory.MasterPage objMasterInstance = (Prepetual_Inventory.MasterPage)Page.Master;
            return objMasterInstance;
        }
    }

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 12

Accepted Solution

by:
techExtreme earned 125 total points
ID: 22816202
Hello,
Looks ok to me, however I have one double, is your master page's class name really 'MasterPage ' ?   because for creating master page you inherit from
System.Web.UI.MasterPage.   I just wanted to confirm the name of your master page

Sample definition of master page code behind:
public partial class abc : MasterPage
{
...
}
So what exactly you have in place of 'abc' shown here in example. If its Prepetual_Inventory.MasterPage, its ok else reply with that line as comment and I'll look into it.
Hope it helped.
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22816289
Try with this directive below your @Page:

<%@ MasterType VirtualPath="PathToYourMasterPageFile" %>
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22820981
Thanks, I would have liked it more if it were an 'A' :(
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question