楼主,你在顶上写的代码有错误吧。 public class ConfigInfoClass { public ConfigInfoClass() { } public static string LoginPage = "CSDN.css"; }<link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>"> 这个ConfigInfoClass.CSS 从哪里来?? 是不是应该写成:ConfigInfoClass。LoginPage ?? 再有,你应该用属性把它封装起来吧?否则小心被改了。
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里二个版本都测试过
在'ConfigInfoClass'前面加上namespace就可以了
Compiler Error Message: CS0117: 'System.Security.Principal.IPrincipal' does not contain a definition for 'ConfigInfoClass' 没有找到'ConfigInfoClass'的定义,怎么这么多人都看不懂吗?
{
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{};
}
我喜欢把这些东西写在基类页中,以后的页就不用烦了。
public string getcss()
{
return "csdn.css";
}
记得以前是这么做的
小弟是新手,错误的话大家不要笑
{
return ConfigInfoClass.LoginPage;
}
页面: href="<% = getfile() %>">
然后用
类名称.方法名(参数等)
来调用
<HEAD>
<link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>">
......我的眼睛仔细;哈哈 <link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.LoginPage %>">
不会出错,刚试过
主要代码如下:
namespace WebApplication1
{
public class WebForm1
{
.....
} public class cls2
{
public static string strTest = "test string here.";
}
}页面上的代码:
<% = WebApplication1.cls2.strTest %>
如果没有命名空间会出现编译错误。
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#
<link rel="stylesheet" type="text/css"
href="<% = WebApplication3.ConfigInfoClass.LoginPage %>">
WebApplication3是ConfigInfoClass的命名空间。
还有一个方法,
可以在CS文件中写一个PUBLIC变量,取到那个静态变量,
然后在ASPX页面上引用这个变量即可。
但人家要求是不使用这个ASPX 内部的成员变量。而使用同级一个类的静态公共成员变量,
Abac的方法是对的
我也试了一下可行
在页面maillist中有:
<INPUT id="test" type="text" value=<%=OA.TMail.GarbageBox%>>
而其中的TMail是与之在同一目录下的一个类
GarbageBox是一个静态变量,
OA是命名空间
{
...
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),虽然不一定是解决楼主问题的最好办法,希望对你有所启发和帮助。:)
你用的 .net framework 是什么版本?我用的 1.0没有问题!
是不是你的类 ConfigInfoClass 的其他地方引起的问题?
???
别的不是很清楚,不过我觉得这儿写错了吧
应该是ConfigInfoClass.LoginPage
<HEAD>
<link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.LoginPage %>">
......改成这样才行。
在aspx.cs文件中,using youbasicclass
然后在aspx文件中如此:<link rel="stylesheet" type="text/css" href="<% @Response.Write( ConfigInfoClass.CSS)%>">
反正是一个string只要提出来不就OK了。
public class ConfigInfoClass
{
public ConfigInfoClass()
{
}
public static string LoginPage = "CSDN.css";
}<link rel="stylesheet" type="text/css" href="<% = ConfigInfoClass.CSS %>">
这个ConfigInfoClass.CSS 从哪里来??
是不是应该写成:ConfigInfoClass。LoginPage ??
再有,你应该用属性把它封装起来吧?否则小心被改了。
{ 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里二个版本都测试过
没有找到'ConfigInfoClass'的定义,怎么这么多人都看不懂吗?
新定义的方法