Solved

Cannot convert type 'System.Web.UI.MasterPage

Posted on 2008-10-27
6
1,319 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now