• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 865
  • Last Modified:

Trying to pass value to Javascript in a LinkButton

I have a Linkbutton control. When it is clicked I would like to pass a value to a Javascript funcition  to open a pop-up window. Linkbutton and Javascript function are below. I cannot figure out how to pass the studyid (which is basically the text value of the LinkButton) in the OnClientClick=Navigate(???). If I hard code a value it works fine.

Any help would be greatly appreciated.

Jason


function Navigate(StudyID_i) {
            javascript: window.open("TechDetail.aspx?studyid="+ StudyID_i);
        } 

<asp:Linkbutton id="LinkButton1" Text='<%# Eval("StudyID_i") %>' CommandArgument='<%# Eval("StudyID_i")%>'  onclientclick="Navigate(????))" runat="Server" />

Open in new window

0
jazzcatone
Asked:
jazzcatone
2 Solutions
 
Gurvinder Pal SinghCommented:
try

onclientclick="Navigate(this.value)"

or

 onclientclick="Navigate(this.getAttribute('value'))"  
0
 
PagodNaUtakCommented:
Try the below code:
<asp:Linkbutton id="LinkButton1" Text='<%# Eval("StudyID_i") %>' CommandArgument='<%# Eval("StudyID_i")%>'  onclientclick="Navigate(<%# Eval("StudyID_i") %>))" runat="Server" />

Open in new window

0
 
PagodNaUtakCommented:
Typo graphical error.
Please disregard my post above but instead try the below code:
<asp:Linkbutton id="LinkButton1" Text='<%# Eval("StudyID_i") %>' CommandArgument='<%# Eval("StudyID_i")%>'  onclientclick="Navigate(<%# Eval('StudyID_i') %>))" runat="Server" />

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Shinesh PremrajanEngineering ManagerCommented:
you need to define it in single quotes else JS will throw an error, something like this

onclientclick="Navigate('<%# Eval('StudyID_i') %>'))"
0
 
PagodNaUtakCommented:
@shinug,

That is what I posted, please check the post of others before posting...
0
 
ProculopsisCommented:

This should be as simple as:

  onclientclick="Navigate( this.innerText );"
0
 
jazzcatoneAuthor Commented:
onclientclick="Navigate( this.innerText );"  Seems to be the best solution. At least for me. Thank you all for your help with this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now