Default.aspx.csusing System;
using System.Data.SqlClient;namespace _09_01
{
    class Class_09_01
    {
        public static void Main(String[] args)
        {
            string test = "pp";
            \\content......
        }
}
然后 在Default.aspx中怎么调用变量test?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="_09_01" %>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>aspx</title>
</head><body>
<%response.write ("test="&test&"<br>")%>
</body>
</html>

解决方案 »

  1.   

    把test定义成public类型的。才可以在前台用。
      

  2.   

    改成这样,public string test = "pp"; 但是报错,
    ...
    public static void Main(String[] args) 
            {   \\这儿报错, CS1513: } expected.....
      

  3.   

    是很乱,整理一下Default.aspx.cs using System; 
    using System.Data.SqlClient; namespace _09_01 

        class Class_09_01 
        { 
            public static void Main(String[] args) 
            { 
                public string test = "pp";             \\content...... 
            } 

    然后 在Default.aspx中怎么调用变量test? 
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="_09_01" %> 
    .......
    <%response.write ("test="&test&" <br>")%> 
    ......
      

  4.   

    你这确实不叫自定义空间。
    而且那个后台代码写不对。
    后台:
    namespace _09_01 

       public  class Class_09_01 
        { 
            public string test = "pp"; 
            private void Page_Load(object sender, System.EventArgs e)
    {
       // ページを初期化するユーザー コードをここに挿入します。
    }
    } 前台:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="_09_01" %> 
    <!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> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>aspx </title> 
    </head> <body> 
    <div><%=test%</div>
    </body> 
    </html> 
    这样试试。
      

  5.   

    我写了一个简单的,调试了一下。好使。你看看吧。
    前台:<html>
      <head>
        <title>WebForm2</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name=vs_defaultClientScript content="JavaScript">
        <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
      </head>
      <body MS_POSITIONING="GridLayout">

        <form id="Form1" method="post" runat="server">
    <div><%=test%></div>     </form>

      </body>
    </html>
    后台:
    namespace WebApplication5
    {
    /// <summary>
    /// WebForm2 の概要の説明です。
    /// </summary>
    public class WebForm2 : System.Web.UI.Page
    {
    public string test="aabbcc"; -------就这句有用。剩下的都是自己生成的。
    private void Page_Load(object sender, System.EventArgs e)
    {
    // ページを初期化するユーザー コードをここに挿入します。
    } #region Web フォーム デザイナで生成されたコード 
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: この呼び出しは、ASP.NET Web フォーム デザイナで必要です。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
    /// コード エディタで変更しないでください。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    }
    }
      

  6.   

    大哥,我说的是自定义空间,我没说自定义控件呀!
    to huohua123
    还有,你那是vs 2007了,我的是2005,调用的代码差别好大呀,
      

  7.   

    这样还是不行:
    Default.aspx.cs 中using System; 
    using System.Data.SqlClient; namespace _09_01
    {
        public class Class_09_01 : System.Web.UI.Page     {
             public string test = "pp";
            private void Page_Load(object sender, System.EventArgs e)
            { }
        }
    }
    然后 在Default.aspx中怎么调用变量test? 
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="_09_01.Class_09_01" %> 
    ....... 
    <%response.write ("test="&test&" <br>")%> 
     报错信息,public class Class_09_01 : System.Web.UI.Page 
    CS0260: Missing partial modifier on declaration of type '_09_01.Class_09_01'; another partial declaration of this type exists
      

  8.   

    谢谢各位,可以了
    太高兴了,但是感觉asp.net还多东东怪怪的,看不怎么明白Default.aspx.csusing System;
    using System.Data.SqlClient;
    namespace _09_01
    {
        public partial class Class_09_01 : System.Web.UI.Page
        {
            public string test = "pp";
        }
    }Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="_09_01.Class_09_01" %>
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>aspx</title>
    </head><body>
    <%Response.Write("strConn="+test);%>
    </body>
    </html>