Linux 更改母版页 <a href 链接来自内容页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change master page <a href link from content page
提问by Nick Kahn
i have this on my master.page
我在我的 master.page 上有这个
<ul class="menu">
<li class="first" runat="server" id="Li2">
<a runat="server" id="A1" href="../NewEntry.aspx">Create a New Entry</a>
</li>
</ul>
when i go to content page ("NewEntry.aspx") i want the link name to be changed to "Update Entry"
当我转到内容页面(“NewEntry.aspx”)时,我希望将链接名称更改为“更新条目”
<ul class="menu">
<li class="first" runat="server" id="Li2">
<a runat="server" id="A1" href="../UpdateEntry.aspx">Update Entry</a>
</li>
</ul>
any feedback?
任何反馈?
采纳答案by egrunin
Make the link an asp:Hyperlink. Then have the master page expose a function or property:
将链接设为 asp:Hyperlink。然后让母版页公开一个函数或属性:
public void SetLink(string href, string text)
{
A1.NavigateURL = href;
A1.Text = text;
}
Call the function from the main page.
从主页调用该函数。
回答by Nick Kahn
You can use a hyperlink control <asp:hyperlink>
and set the url as well as the text values.
您可以使用超链接控件<asp:hyperlink>
并设置 url 以及文本值。
回答by Nathan Donze
I would recommend handling this as a HyperLink control as others have mentioned. If for some reason you must handle this as a server-side HTML anchor, you can access it using the following code from your webform code-behind:
我建议将其作为其他人提到的 HyperLink 控件来处理。如果由于某种原因您必须将其作为服务器端 HTML 锚点来处理,您可以使用 Web 表单代码隐藏中的以下代码访问它:
HtmlAnchor link = (HtmlAnchor)(this.Master).FindControl("A1");
link.InnerText = "Update Entry";
回答by eglasius
You can also define a content place holder where you have "Create a New Entry". Leave that as the default inside that place holder, and only in the content page set content for it to Update Entry.
您还可以定义一个内容占位符,您可以在其中“创建新条目”。将其保留为该占位符内的默认值,并且仅在内容页面中将其设置为更新条目。