Grace Huang
Grace Huang

Reputation: 5699

Pass a variable from Site.Master.cs to Site.Master

I'm new to C# web development. Please bear with me.

I'm trying to reference a param from Site.Master.cs in Site.Master, so that in Site.Master page, I can do:

<%
  if (someParam == true) {
%>

some HTML code

<%
 }
%>

The param someParam is the one I want to pass from Site.Master.cs.

Thanks!

Upvotes: 0

Views: 1064

Answers (3)

MUS
MUS

Reputation: 1450

Follow the below code example.

Site.Master.cs

protected bool someParam
{
    get;
    set;
}

Site.Master page

<%
  if (someParam) {
%>

some HTML code

<%
 }
%>

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190976

You can use a LiteralControl.

<asp:Literal ID="myControl" runat="server">
// Some html here.
</asp:Literal>

Then in the codebehind - set the Visible property appropriately.

Upvotes: 1

Hans Kesting
Hans Kesting

Reputation: 39329

Use a class-level field (or better: property) with visibility at least "protected" (not private).

Upvotes: 2

Related Questions