views:

1080

answers:

6

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.

A: 

Hai, see this if it helps http://forums.asp.net/p/1490115/3505218.aspx

Pandiya Chendur
Thanks! I'm using a method from post #2 and it doesn't work. I want to figure out where am I wrong..
abatishchev
+1  A: 

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" />
Phaedrus
Next is being rendered: <a id="ctl00_commonForm_ctl01_urlRefuse">Refuse</a>.Thanks for tip. I used it. The same result..
abatishchev
Are you trying to use values from the query string? Did you try and use Request["id"] instead of Eval("id")?
Phaedrus
Try adding Page.DataBind() to your Page_Load.
Phaedrus
I tried this myself, it worked. Make sure you have valid data in your query string parameters.
Phaedrus
@Phaedrus where he is using the hyperlink within a datalist,gridview or the page
Pandiya Chendur
abatishchev
HttpUtility.UrlEncode(Eval("type") have u tried this
Pandiya Chendur
(string)Eval("type") works only after this.DataBind() on Page_Load(). It works but it sucks :)
abatishchev
A: 

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>  
Pandiya Chendur
A: 

Try this:

HttpUtility.UrlEncode(Eval("type")
Pandiya Chendur
A: 

Try this it worked for me:

Eval("type").ToString()
Pandiya Chendur
+1  A: 

This worked for me

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