就是如何让页面HTML的<title>???</title>的???显示为aspx.cs里的Label绑定的值?
解决方案 »
- 使用相对地址导致伪静态后找不到css和图片
- 绘制奥运五环图案
- GridView购物车使用js进行产品数量的增加问题
- 问一个超级简单的问题
- 谁能给我一个动态生成gridview模板列并绑定一个dropdownlist控件的例子?
- *************如何在加载IE窗体的时候,隐藏工具栏和菜单*************
- 我做了一个自定义的控件扩展了GridView控件,我现在要为这个控件做一个皮肤
- 招聘兼职
- 急!急! Response.Write(javascript)的问题!
- 为什么我加入TreeView后,运行时显示网页上有错误??? ?
- 提供程序无法确定 String 值。
- 急!!简单!!如何在后台代码中实现在特定的frame中打开一个网页??
s="mytitle";
document.title = s;
</script>
<%=title%>
<title>xxx.cs
public string title="ASD";
绝对行,我测试通过
Page_Load:Page.DataBind();
Page.Header.Title = "你要的值";
绝对行,我测试通过2、
<title><%=title%><title>CS代码
public string strtitle="";private void Page_Load(object sender, EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
strtitle="ssss";
}
}
protected void Page_Load(object sender, EventArgs e)
{
Page.Header.Title = "testHeader";
page_Load里试的,VS2005 调试环境
<title><%#Label1.Text %></title>
</asp:Panel>Page_Load:aaa.DataBind();
<head runat="server">
<asp:Panel id="aaa" runat="server">
<title><%#Label1.Text %></title>
</asp:Panel>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="<%#AA %>"></asp:Label></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _a : System.Web.UI.Page
{
public string AA = "ok";
protected void Page_Load(object sender, EventArgs e)
{
Label1.DataBind();
aaa.DataBind(); }
}
——————————————————————————————————————————
A: 这不等于aspx里边的<asp:Label>的值!不论是aspx还是ascx或者自定义控件,你都可以这样写: this.Page.ClientScript.RegisterStartupScript(this.GetType(),"setTitle",
"window.document.title='" + yourLabel.Text.Replace("'","\\'")+"';");
{
return ....
}
<head runat="server" id="Head1">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LblHead" runat="server" Text="第一次加载."></asp:Label>
<asp:TextBox ID="TxtHead" runat="server"></asp:TextBox>
<asp:Button ID="BtnHead" runat="server" OnClick="BtnHead_Click" Text="Change Title" /></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//初始Title
this.Head1.Title = LblHead.Text;
}
/// <summary>
/// 更改Title
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnHead_Click(object sender, EventArgs e)
{
this.Head1.Title = TxtHead.Text;
}
}
<asp:Panel id="Label1" runat="server">
<title><%#Label1.Text %></title>
</asp:Panel>
Label1.DataBind();
<title runat="server" id="mytitle">无标题页</title>
这时候代码中就立刻出现了mytitle控件,并且它的类型就是 HTMLTitle,所以使用Text属性设置标题内容。在asp.net1.1下,设计器上的写法与上边一样,但是codebehind代码中必须要自己声明其类型:
protected HtmlGenericControl mytitle;
然后就可以直接操纵标题控件(因为页面会给这个变量传递准确的控件)。由于是HtmlGenericControl 类型,所以使用InnerText属性设置标题内容。
<title><%=title%><title>CS代码
public string strtitle="";private void Page_Load(object sender, EventArgs e)
{
// 在此处放置用户代码以初始化页面strtitle="ssss";}
最简单方便的方法!
<title><%= Label1.Text %></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Text="abc" runat="server"></asp:Label>
</div>
</form>
</body>
<title id="Titile" runat="server"></title>
之后你就直接操作Page.Title.InnerHTML吧,因为服务器端已经将它识别为一个通用控件。需要注意的是,VS遇到这样的页面会主动帮你把它改回<title></title>。ASP.NET 2.0:
官方引入了上述机制,整个Header就是一个控件,Page.Header.Title直接操作就是了。
正好是数据绑定
这属于 绑定简单变量
语法为:<%#Name#>
<asp:label text='<%#Label.text>' runat="server"/>