Asp.net 从 C# 代码中获取变量

本文关键字:获取 变量 代码 net Asp | 更新日期: 2023-09-27 18:32:35

我想在asp代码中使用继承的变量

我的代码看起来像那样

namespace WebApplication2
{
    public class Global : System.Web.HttpApplication
    {
    public bool abcdef = true;   // my variable that i want to use in my asp code      
    ...
    }
}

ASP 部分如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">   
<% 
if(webapplication1.main.abcdef) //this is incorrect, i want to correct that 
{%> 
my first web page 
<%}
else 
{%> 
my second web page 
<%} %>
</html>

如何在 asp 代码中使用变量abcdef

Asp.net 从 C# 代码中获取变量

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" MasterPageFile="MasterPage.Master"
    Inherits="Namespace.YouClass" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script>
if(<%#this.abcdef%>)
{
//do your work
}
</script>