English 中文(简体)
Set Property Value on Master Page from Content Page
原标题:

I tried following the advice posted here: Set Property Value on Master Page from Content Page.

Specifically the last post about creating a class. However, visual studio keeps giving me an error on my default.aspx.cs page when i try to set the value:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  

public partial class _Default : BasePage  
{  

    protected override int NavHighlight  
    {  
        get { return new{0} ; }  
    }  

    protected void Page_Load(object sender, EventArgs e)  
    {  

    }  
}  

It throws an error on new, the error being: cannot inplicity convert anonymoustype#1 to int

Can someone tell me what i might have done wrong here?

Here s what my class looks like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for BasePage
/// </summary>
public abstract class BasePage : System.Web.UI.Page
{
    protected abstract int NavHighlight { get; }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (this.Master != null)
        { 
            //value assignment 
        }
    }

 public BasePage()
 {
  //
  // TODO: Add constructor logic here
  //
 }
}

Thanks.

问题回答

Did you cast your master page as shown in your referenced question?

The correct code should be

protected override int NavHighlight  
{  
    get { return 0; }  
}

Not

protected override int NavHighlight  
{  
    get { return new{0}; }  
}

It has nothing to do at all with Master Page / Content Page.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签