?
Solved

Cannot convert type 'System.Web.UI.MasterPage

Posted on 2008-10-27
6
Medium Priority
?
1,408 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 12

Accepted Solution

by:
techExtreme earned 375 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

741 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