Solved

Trying to pass value to Javascript in a LinkButton

Posted on 2011-02-23
7
839 Views
Last Modified: 2012-05-11
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
Comment
Question by:jazzcatone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34967390
try

onclientclick="Navigate(this.value)"

or

 onclientclick="Navigate(this.getAttribute('value'))"  
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34967432
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
 
LVL 8

Assisted Solution

by:PagodNaUtak
PagodNaUtak earned 100 total points
ID: 34967436
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 34967483
you need to define it in single quotes else JS will throw an error, something like this

onclientclick="Navigate('<%# Eval('StudyID_i') %>'))"
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34967594
@shinug,

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

Accepted Solution

by:
Proculopsis earned 400 total points
ID: 34968622

This should be as simple as:

  onclientclick="Navigate( this.innerText );"
0
 

Author Comment

by:jazzcatone
ID: 34969984
onclientclick="Navigate( this.innerText );"  Seems to be the best solution. At least for me. Thank you all for your help with this.
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question