views:

82

answers:

1

I have a ASP.NET page that uses the include method for header. I am adding a JS variable that I access from JS functions

In head.htm

<script language="javascript" type="text/javascript">
    var render=<%= RenderProperty %>;
</script>

The RenderProperty is a method in the base page class (a .cs file that inherits from System.Web.UI.Page)

It looks something like this:

private bool _renderProp = false; 
public bool RenderProperty 
{
  get
  {
    return _renderProp;
  }
  set
  {
    _renderProp = value;
  }
}

On a page by page basis, I set the RenderProperty in the Page_Load of a aspx page

protected void Page_Load(object sender, EventArgs e)
{
  RenderProperty = true;
}

I get a compile time error that says:

The name 'RenderProperty' does not exist in the current context 
C:\...\head.htm
A: 
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 : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public string pepe
    {
        get { return "ddd"; }
    }
}


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%=this.pepe %>
    </div>
    </form>
</body>
</html>
andres descalzo
Obj as in reference to BaseClass?
yes, must be declared, try with "this", but it always has and to be a property of an object
andres descalzo
If I use this.RenderProperty, I getError 53 'ASP.shared_aspx_error_aspx' does not contain a definition for RenderProperty and no extension method RenderProperty accepting a first argument of type 'ASP.shared_aspx_error_aspx' could be found (are you missing a using directive or an assembly reference?) C:\...\T_Head.htm 17
this example work ok
andres descalzo
try with "var render='<%=this.RenderProperty %>';
andres descalzo
Yes,I did try that. No luck. I think it appears to be something related to inheritence
DotnetDude