我在我的母版页上有一个lablel和各种页面的链接
<ul id="navigation">
<li><span class="active">Overview</span></li>
<li><a href="AdminHome.aspx">Home</a></li>
<li><a href="LoginInfo.aspx">Register</a></li>
<li><a href="ProductCategory.aspx">Category</a></li>
<li><a href="ProductSubCategory.aspx">Sub-Category</a></li>
<li><a href="ProductSubCategory2.aspx">Sub-Category2</a></li>
<li><a href="CompanyInfo.aspx">Company</a></li>
<li><a href="ProductInfo.aspx">Product</a></li>
<li><a href="ProductStock.aspx">Stock</a></li>
<li><a href="ProductPhoto.aspx">Photo</a></li>
</ul>
<div id="content" class="container_16 clearfix">
<div class="grid_16">
<h2>
<asp:Label ID="lblpagename" runat="server" Text=""></asp:Label> </h2>
<p class="error">
Something went wronk.</p>
</div>
</div>
现在我希望每当我点击任何链接时,页面名称如“Home”,“Register”......出现在标签文本中
答案 0 :(得分:2)
试试这个:
string url = Request.Url.AbsolutePath.ToString();
int start=url.LastIndexOf('/');
int length = url.Length - url.LastIndexOf('/');
string pageName = url.Substring(start, length).Replace("/","");
Response.Write(pageName);//or label1.text=pageName;
答案 1 :(得分:1)
您可以在page_load
的内容页面中将其设置为Page.Title protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "Some Title";
}
并在page_load事件的主页上阅读
protected void Page_Load(object sender, EventArgs e)
{
lblpagename.Text = Page.Title;
}
答案 2 :(得分:0)
您必须根据页面名称添加每个页面的文本。您可以像这样访问儿童母版页的控件
Label lblMessage = new Label();
lblMessage = (Label)Master.FindControl("lblpagename");
lblMessage.Text = DropDownList1.SelectedItem.Text;