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")

3
  • Where on page (inside what controls) is this link situated? And how are you retrieving the value? Commented Mar 3, 2014 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); } Commented Mar 3, 2014 at 17:31
  • I believe the method needs to be public to be used on the page Commented Mar 3, 2014 at 20:09

1 Answer 1

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() %>"
Sign up to request clarification or add additional context in comments.

2 Comments

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?
italic bold NavigateUrl='<%# "Link.aspx?name=" + (string)Eval("name") %>' In fact, in did work this way. So thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.