0

I have created a new Web Application in Visual Studio. But I can not access to a variable from a Masterpage content to the codebehind of the same masterpage :

I have a .master page :

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Intra.Private.Site1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder> </head> <body>
    <form id="form1" runat="server">
    <div>
        <%=Test %>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form> </body> </html>

The .master.cs fil contains :

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

namespace Intra.Private
{
    public partial class Site1 : System.Web.UI.MasterPage
    {

        public string Test = "";
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

The "<%=Test %>" methods doesn't works : I get the error "Test" doesn't exist in the current context ...

I have already tried to declare protected string Test instead of public string Test but it's not better...

Do you have any idea ?

user1592596
  • 65
  • 1
  • 10
  • Have you looked at [this](https://stackoverflow.com/questions/7406961/how-to-call-a-variable-in-code-behind-to-aspx-page)? – sunilsachdeva Sep 04 '17 at 06:33
  • Unfortunately yes... I've tried with protected and with all the suggestion in this article... it seams specific to Masterpage and Web App C#... ? – user1592596 Sep 04 '17 at 19:04

0 Answers0