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 ?