HyperLink with NavigateUrl with Eval(). Where is the mistake?
Asked Answered
H

6

24

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.

Henson answered 22/11, 2009 at 18:16 Comment(7)
Hai, see this if it helps http://forums.asp.net/p/1490115/3505218.aspxNickelic
Thanks! I'm using a method from post #2 and it doesn't work. I want to figure out where am I wrong..Henson
Id prperty of ur hyperlink is missing... Is that causes error i dont know...Nickelic
@Pandiya: Sounds mysteriously and in the same time - realistic. But unfortunately didn't help.Henson
NavigateUrl='<%#Eval("type","id", "~/Refuse.aspx?type={0}&id={1}") %>'Nickelic
Try NavigateUrl='<%#string.Format("Sync.aspx?Msg={0}", HttpUtility.UrlEncode(Eval("Msg"))%>'Nickelic
Where you use the hyper within a datalist,gridview or the pageNickelic
A
63

this is working great

NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'
Aeciospore answered 10/2, 2011 at 14:2 Comment(1)
I stopped using web forms years ago, and yet I come years later to learn something like this was so easy.Pleach
T
17

This worked for me

NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'
Tyndall answered 23/10, 2010 at 10:58 Comment(0)
C
4

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" />
Callida answered 22/11, 2009 at 18:46 Comment(7)
Next is being rendered: <a id="ctl00_commonForm_ctl01_urlRefuse">Refuse</a>. Thanks for tip. I used it. The same result..Henson
Are you trying to use values from the query string? Did you try and use Request["id"] instead of Eval("id")?Callida
Try adding Page.DataBind() to your Page_Load.Callida
I tried this myself, it worked. Make sure you have valid data in your query string parameters.Callida
@Callida where he is using the hyperlink within a datalist,gridview or the pageNickelic
I already understood that I have to use Request["id"]. I do this. And current url where I'm testing is /Approve.aspx?type=request_exchange&id=2 a page loads a control without any GridView or other ViewsHenson
(string)Eval("type") works only after this.DataBind() on Page_Load(). It works but it sucks :)Henson
N
-1

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>  
Nickelic answered 22/11, 2009 at 18:52 Comment(0)
N
-1

Try this:

HttpUtility.UrlEncode(Eval("type")
Nickelic answered 22/11, 2009 at 18:55 Comment(0)
N
-1

Try this it worked for me:

Eval("type").ToString()
Nickelic answered 22/11, 2009 at 19:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.