1

我想在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>

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

4

1 回答 1

1
<%@ 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>
于 2012-04-30T06:25:25.683 回答