Solved

Cannot convert type 'System.Web.UI.MasterPage

Posted on 2008-10-27
6
1,362 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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