Solved

Cannot convert type 'System.Web.UI.MasterPage

Posted on 2008-10-27
6
1,351 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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