带有 NavigateUrl 和 Eval() 的超链接。错误在哪里?

发布于 2024-08-12 02:13:46 字数 663 浏览 4 评论 0原文

首先,我在 Page_Load() 的代码隐藏中更改了 HyperLink.NavigateUrl

但是当我决定在设计中使用 Eval() 方法来完成它之后。

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />

或者

<asp:HyperLink ID="urlRefuse" runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />

其中 idtype - 是来自 Request 的变量。

但这不起作用。仅显示原始文本“拒绝”。我的错误在哪里?提前致谢。

First I was changing HyperLink.NavigateUrl in code-behind on Page_Load().

But after I decided to do it in design using Eval() method.

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />

or

<asp:HyperLink ID="urlRefuse" runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />

where id and type - are variables from Request.

But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance.

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

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

发布评论

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

评论(6

并安 2024-08-19 02:13:46

这很好用

NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'

this is working great

NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'
哭了丶谁疼 2024-08-19 02:13:46

这对我有用

NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'

This worked for me

NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'
拍不死你 2024-08-19 02:13:46

尝试在浏览器中查看Source,href 中向客户端呈现的内容是什么?是你所期望的吗?如果您尝试使用请求集合中的变量,则无法使用 Eval,您需要使用请求查询字符串参数。

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />

Try and ViewSource in your browser, what's being rendered to the client in your href? Is it what you expected?. If you are trying to use variables from the request collection you can't use Eval, you need to use the Request query string parameters.

<asp:HyperLink runat="server"
     NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
背叛残局 2024-08-19 02:13:46

试试这个:

HttpUtility.UrlEncode(Eval("type")

Try this:

HttpUtility.UrlEncode(Eval("type")
书信已泛黄 2024-08-19 02:13:46

试试这个:

<asp:HyperLink ID="HyperLink2" runat="server" onclick='<%# String.Format("AcceptUser({0},{1})",Eval("UserId"), Eval("TsId")) %>' NavigateUrl="javascript:void(0)" Visible='<%# (bool)Eval("CanDelete") %>'>Accept</asp:HyperLink>  

Try this one:

<asp:HyperLink ID="HyperLink2" runat="server" onclick='<%# String.Format("AcceptUser({0},{1})",Eval("UserId"), Eval("TsId")) %>' NavigateUrl="javascript:void(0)" Visible='<%# (bool)Eval("CanDelete") %>'>Accept</asp:HyperLink>  
久而酒知 2024-08-19 02:13:46

试试这个它对我有用:

Eval("type").ToString()

Try this it worked for me:

Eval("type").ToString()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文