views:

168

answers:

2

Hello,

I tried following the advice posted here: http://stackoverflow.com/questions/1071920/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.

A: 

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

No Refunds No Returns
sorry - i missed that (and still am missing it). where is that being done in the example i linked to? Thanks for the help.
Merk
((MyMasterPageType)Page.master).Roles = "blah blah";
No Refunds No Returns
Ah ok - last comment. Where would that be done in the code then? I dont really understand what that line of code is doing. Sorry for my newbishness.Just to be clear - i'm trying to follow the example as given by chakrit on that page. thanks for the help
Merk
Hey don - any chance you can explain where that line of code you mentioned belongs? I dont really understand what it's doing or if it applies to the suggestion as posted by chakritthanks
Merk
A: 

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.

Amry