cs文件的Page_Load 里的变量 怎么在aspx里读出来
CS文件:
protected void Page_Load(object sender, EventArgs e)
{
string DomainName = Request.ServerVariables[ "SERVER_NAME "];
string selsql = "Select title from table Where id= " + id + " ' ";
SqlConnection con = Sql.GetConnection();
con.Open();
SqlCommand cmd = new SqlCommand(selsql, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string Title = dr[ "Title "].ToString();
}
else
{
Response.Write( "该信息不存在! ");
}
dr.Close();
con.Close();
}
ASPX文件:
<title> <%=Title%> </title>
这样读不出来,提示Title不存在
------解决方案--------------------public string Title = " ";
if (dr.Read())
{
string Title = dr[ "Title "].ToString();
}
------解决方案--------------------public string title ;
protected void Page_Load(object sender, EventArgs e)
{
title = dr[ "Title "].ToString();
}
<title> <%=title%> </title>
title必须是cs文件中的全局变量。
------解决方案--------------------如果你用的是2005的话,建议可以直接这样在后台设置title
this.Head.Title = "sdfafa ";