Solved

Trying to pass value to Javascript in a LinkButton

Posted on 2011-02-23
7
822 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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 17

Expert Comment

by:shinuq
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now