1

我的母版页上有一个标签,并且各个页面的链接都像这样

<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>

现在我希望每当我单击任何链接时,页面名称(例如“主页”、“注册”...)都会出现在标签文本中

4

3 回答 3

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;
于 2013-09-06T03:24:35.850 回答
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;   
    }
于 2013-09-06T03:26:14.967 回答
0

您必须根据页面名称添加每个页面的文本。您可以像这样访问子级母版页的控件

Label lblMessage = new Label();
lblMessage = (Label)Master.FindControl("lblpagename");
lblMessage.Text = DropDownList1.SelectedItem.Text;
于 2013-09-06T03:25:08.190 回答