How do you access the variables defined in masterpage.master.vb in masterpage.master

I have a collection of cookies populated with Browserhawk information in masterpage.master.vb, for example:

Dim useCSS as boolean = 0
Response.Cookies("Stylesheets").Value = brHawk.Stylesheets
if Response.Cookies("Stylesheets") = True then useCSS = 1

If Stylesheets True, I set useCSS to 1, if false, I set useCSS to 0 I need to access them in the masterpage.master section, for example:

if useCSS = true 
Then load stylesheet 
else 
Dont load stylesheet

I'm having trouble finding the right syntax to get this to work.

+3
source share
2 answers

You need to set it as a property in order to use it in the markup.

In code:

Private _useCss As Boolean
Public Property UseCss() As Boolean
    Get
        Return _useCss
    End Get
    Set(ByVal value As Boolean)
        _useCss = value
    End Set
End Property

Then in the markup:

    <%  If UseCss = True Then %>
    Your stylesheet link tag here
    <% Else %>
    else could be optional if you won't load anything
    <%  End If %>

Alternatively, you can:

    <%  If UseCss = True Then
            Response.Write("text")
        Else
            Response.Write("something else")
        End If
    %>

- head CSS. .

:

<head runat="server" id="head">
   <%-- whatever you typically place here --%>
</head>

, , :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If useCss Then
        Dim stylesheet As New HtmlGenericControl("link")
        stylesheet.Attributes.Add("rel", "stylesheet")
        stylesheet.Attributes.Add("type", "text/css")
        stylesheet.Attributes.Add("href", "../css/myCssFile.css")
        FindControl("head").Controls.Add(stylesheet)
    End If
End Sub
+3

public use useCSS .

<% if ( useCSS == true ) { %>
  <link rel="stylesheet" href="" type="text/css" media="screen" />
<% } %>

: # Guy:). , VB.

+2

Source: https://habr.com/ru/post/1730854/


All Articles