ASPX文件的执行, 应该是从对应代码类的实列,跟这个类同级的一个类的静态公共成员变量为啥不能访问?? 比较怪异。不值谁能帮我解决这个疑惑。

解决方案 »

  1.   

    protected override void CreateChildControls()
    {

    base.CreateChildControls ();
    this.WebPate = System.Configuration.ConfigurationSettings.AppSettings["BootPath"].ToString();
    try
    {
    Response.Write("<script language=javascript src=\"/webctrl_client/HFLibrary/HFCombo.js\"></script>");
    //统一添加式样文件
    Response.Write(string.Format(Style.strCssPath ,this.WebPate+"/css/IDCOrders.css"));
    Response.Write("<script>" +string.Format(Script.SetWindowTitle,"IDC业务管理系统") +"</script>");
    }
    catch{};
    }
    我喜欢把这些东西写在基类页中,以后的页就不用烦了。
      

  2.   

    试着写一个函数比如:
    public string getcss()
    {
    return "csdn.css";
    }
    记得以前是这么做的
      

  3.   

    或者是否该写成class->css?
    小弟是新手,错误的话大家不要笑
      

  4.   

    在.cs文件中写个函数getfile()来get串值
    {
    return ConfigInfoClass.LoginPage;
    }
    页面: href="<% = getfile() %>">
      

  5.   

    写一个静态方法来返回style名称
    然后用
         类名称.方法名(参数等)
    来调用
      

  6.   

    <HTML>
    <HEAD>
    <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>">
    ......我的眼睛仔细;哈哈 <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.LoginPage %>">
    不会出错,刚试过
      

  7.   

    我测试的结果也是可以直接访问,不过要带命名空间的。
    主要代码如下:
    namespace WebApplication1
    {
     public class WebForm1
     {
       .....
     }  public class cls2
      {
        public static string strTest = "test string here.";
       }
    }页面上的代码:
    <% = WebApplication1.cls2.strTest %>
    如果没有命名空间会出现编译错误。
      

  8.   

    这有个动态调用CSS文件的例子:Define the HEAD-Section as a serverside Control:    <Head runat="Server" id="objHead">...</Head>Declare it in your code-behind:    Protected WithEvents objHead As HtmlGenericControl ' VB.NET
        protected HtmlGenericControl objHead; // C#Assign a LiteralControl containing the Stylesheet-Declaration:    objHead.Controls.Add( _
           New LiteralControl("<link rel=""stylesheet"" " + _
              "type=""text/css"" href=""Style.css"">")) ' VB.NET    objHead.Controls.Add(new LiteralControl(
           "<link rel=\"stylesheet\" "
           + "type=\"text/css\" href=\"Style.css\")) // C#
      

  9.   

    静态成员属于类本身,并不属于类的实例。试试下面的方法吧。
    <link rel="stylesheet" type="text/css" 
    href="<% = WebApplication3.ConfigInfoClass.LoginPage %>">
    WebApplication3是ConfigInfoClass的命名空间。
      

  10.   

    蝈蝈兄,
    还有一个方法,
    可以在CS文件中写一个PUBLIC变量,取到那个静态变量,
    然后在ASPX页面上引用这个变量即可。
      

  11.   

    我比较赞成ylc001(白面包青天) 的意见
    但人家要求是不使用这个ASPX 内部的成员变量。而使用同级一个类的静态公共成员变量,
    Abac的方法是对的
    我也试了一下可行
    在页面maillist中有:
    <INPUT id="test" type="text" value=<%=OA.TMail.GarbageBox%>>
    而其中的TMail是与之在同一目录下的一个类
    GarbageBox是一个静态变量,
    OA是命名空间
      

  12.   

    另外,如果你需要完全动态由程序控制诸如此类的属性,可以令<link runat="server" .../>,同时给它赋一个id,在code behind类中声明一个类成员GenericHtmlControl id,这样在程序中你就可以通过这个id自由控制这个置标的各种属性了。如:default.aspx:<link runat="server" id="csslink" rel="stylesheet"/>default.aspx.cs:class WebForm1: Page
    {
      ...
      protected HtmlGenericControl csslink;  public void Page_Load(...)
      {
        csslink.Attributes["href"] = "default.css";
        ...
      }...}output html:<link id="csslink" rel="stylesheet" href="default.css"/>这种方法可以极其灵活的在后台程序中控制页面中的任何html对象(只要runat=server并有id),虽然不一定是解决楼主问题的最好办法,希望对你有所启发和帮助。:)
      

  13.   

    发一个post请求 载服务端运行你的类对象 返回结果到客户端 用javascript 调用DHTML掉用CSS
      

  14.   

    将配制类,做成一个单例global.asa.cs文件中调用即可。
      

  15.   

    ghj1976 (蝈蝈俊.net)  
    你用的 .net framework 是什么版本?我用的 1.0没有问题!
    是不是你的类 ConfigInfoClass 的其他地方引起的问题?
      

  16.   

    <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>">
    ???
    别的不是很清楚,不过我觉得这儿写错了吧
    应该是ConfigInfoClass.LoginPage
      

  17.   

    <HTML>
    <HEAD>
    <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.LoginPage %>">
    ......改成这样才行。
      

  18.   

    同意 henryfan1(每天好心情(*_*)) 做法,做到基类中去,然后继承过来较好。
      

  19.   

    可以这样的。
    在aspx.cs文件中,using youbasicclass
    然后在aspx文件中如此:<link rel="stylesheet" type="text/css" href="<% @Response.Write( ConfigInfoClass.CSS)%>">
    反正是一个string只要提出来不就OK了。
      

  20.   

    楼主,你在顶上写的代码有错误吧。
    public class ConfigInfoClass
    {
    public ConfigInfoClass()
    {
    }
    public static string LoginPage = "CSDN.css";
    }<link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>">
    这个ConfigInfoClass.CSS 从哪里来??
    是不是应该写成:ConfigInfoClass。LoginPage ??
    再有,你应该用属性把它封装起来吧?否则小心被改了。
      

  21.   

    1.0没问题 1.1版本也没有任何问题core.cspublic class Core
    {   private static string m_OpenDb=string.Empty; public static string OpenDb
    {    
    get
    {
    if(m_OpenDb==string.Empty)
    {
    try
    {
    m_OpenDb =System.Configuration.ConfigurationSettings.AppSettings["ConnectionDataBase"];
    }
    catch
    {
    m_OpenDb=string.Empty;
    }
    }
    return m_OpenDb;
    }
    }
    }
    dbapi.cspublic class DBAPI
    {   
    string condb="";
    public DBAPI()
    {
    if(Core.OpenDb!=string.Empty)
    condb=Core.OpenDb;
    }}
         一直很正常的用,asp.net里二个版本都测试过
      

  22.   

    在'ConfigInfoClass'前面加上namespace就可以了
      

  23.   

    Compiler Error Message: CS0117: 'System.Security.Principal.IPrincipal' does not contain a definition for 'ConfigInfoClass'
    没有找到'ConfigInfoClass'的定义,怎么这么多人都看不懂吗?
      

  24.   

    首先在与你这个页面关联的类中(.cs文件)添加一个方法,在这个方法中调用ConfigInfoClass中的配置信息 并返回此信息,页面中<% = ConfigInfoClass.CSS %>换成
    新定义的方法
      

  25.   

    <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.LoginPage %>">