0

I need to send a value to Link_Click (which is a method) by clicking on this link :

<asp:HyperLink ID="TheLink" runat="server" Text='<%# Eval("ID") %>' onclick="Link_Click"></asp:HyperLink>

the Value is: Eval("name")

Servy
  • 202,030
  • 26
  • 332
  • 449
user3375869
  • 11
  • 1
  • 5
  • Where on page (inside what controls) is this link situated? And how are you retrieving the value? – Andrei Mar 03 '14 at 17:21
  • inside a listview, and, for the value, here's the method Link_Click protected void Link_Click(object sender, EventArgs e) { string strName = ""; // strName is the value I want to get from the link string url; url = "Link.aspx?name=" + strName; Response.Redirect(url); } – user3375869 Mar 03 '14 at 17:31
  • I believe the method needs to be public to be used on the page – deltree Mar 03 '14 at 20:09

1 Answers1

0

onclick is a client-side javascript event handler, so you can do it this way:

onclick="<%= "Link_Click(" + Eval("name") + ")" %>

Otherwise, HyperLink navigates to another page, and you need to add the NavigateUrl property to a value like:

NavigateUrl="Some.aspx?name=<%# Eval("name") %>"

if that will work, but I think you need to do it as:

NavigateUrl="<%= "Some.aspx?name=" + Eval("name").ToString() %>"
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Then please update your question to include additional information, such as how you are expecting to receive the value... The approach I took was to grab the value via `Request.QueryString("name")`, so are you saying it is erroring, the value is blank, or what you expected to happen isn't happening? – Brian Mains Mar 03 '14 at 21:32
  • _italic_ **bold** `NavigateUrl='<%# "Link.aspx?name=" + (string)Eval("name") %>'` In fact, in did work this way. So thank you very much – user3375869 Mar 04 '14 at 14:13