在 asp:hyperlink 中分配声明值时出现问题。错误:这不是 scriptlet。将输出为纯文本

发布于 2024-09-13 17:31:37 字数 376 浏览 1 评论 0原文

我正在尝试这样做:

<asp:HyperLink NavigateUrl='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>' runat="server" Text='<%= GetProfileImage(WebContext.CurrentUser.AccountId) %>'></asp:HyperLink> 

但收到错误:

这不是脚本。将输出为 纯文本。

当我将鼠标悬停在声明性陈述上时。

有什么想法吗?谢谢。

I am trying to do this:

<asp:HyperLink NavigateUrl='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>' runat="server" Text='<%= GetProfileImage(WebContext.CurrentUser.AccountId) %>'></asp:HyperLink> 

But am getting the error:

this is not scriptlet. will output as
plain text.

when I mouse over my declarative statements.

Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剪不断理还乱 2024-09-20 17:31:37

不能使用 <%= ... %> 文字设置服务器端控件的属性。

相反,您可以使用普通(客户端) 标记,如下所示:

<a href="<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>"><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>

如果 GetProfileImage 不返回 HTML 标记,请确保对其进行转义。

You cannot use <%= ... %> literals to set properties of server-side controls.

Instead, you can use a normal (client-side) <a> tag, like this:

<a href="<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>"><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>

If GetProfileImage doesn't return HTML tags, make sure to escape it.

你曾走过我的故事 2024-09-20 17:31:37

您可以使用数据绑定语法<%# %>。只需确保您的超链接位于数据绑定控件(例如 ListView 项模板)中,或者您从代码隐藏中显式调用控件上的 DataBind() 即可。

You can use data binding syntax <%# %>. Just be sure that your hyperlink is either in a databound control, such as a ListView item template, or that you explicitly call DataBind() on the control from code-behind.

初雪 2024-09-20 17:31:37

您仍然可以填充如果您提供 IDrunat="server" 属性。然后,您可以从代码隐藏中设置超链接的任何属性。

ASP 代码:

<asp:HyperLink ID="myLink" runat="server"/>

隐藏代码:

public void Page_Init()
{
    myLink.NavigateURL = WebContext.RootUrl + WebContext.CurrentUser.UserName;
    myLink.Text = GetProfileImage(WebContext.CurrentUser.AccountId);
}

You can still populate an <asp:HyperLink> if you provide the ID and runat="server" properties. You can then set any property of the HyperLink from code-behind.

ASP Code:

<asp:HyperLink ID="myLink" runat="server"/>

Code-behind:

public void Page_Init()
{
    myLink.NavigateURL = WebContext.RootUrl + WebContext.CurrentUser.UserName;
    myLink.Text = GetProfileImage(WebContext.CurrentUser.AccountId);
}
糖果控 2024-09-20 17:31:37
<a href='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>'><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>
<a href='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>'><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文