Solved

Pass Variable to Javascript from ASP.NET

Posted on 2014-12-08
8
127 Views
Last Modified: 2014-12-13
I have what is probably a simple syntactical problem.  As background, the button is in a nested ListView, but it seems like it should be pretty straightforward.  The js function simply takes the TripID variable and opens a popup window with the data.  The error message is that the server tag is not well formed which makes me think it is a matter of quotes and single ticks but I'm not having any luck finding an example of how best to fix this.  Thanks for the help.

<asp:LinkButton ID="btnRegistered" runat="server" Text="See Who Has Registered" CssClass="readmore" OnClientClick="listWindowOpen('<%# Eval("TripID") %>');return false;" UseSubmitBehavior="False" />
0
Comment
Question by:AJ0718
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40487353
<asp:LinkButton ID="btnRegistered" runat="server" Text="See Who Has Registered" CssClass="readmore" OnClientClick="listWindowOpen('<%# Eval(""TripID"") %>');return false;" UseSubmitBehavior="False" /> 

Open in new window

0
 

Author Comment

by:AJ0718
ID: 40487420
Nope; same parser error.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40487454
<asp:LinkButton ID="btnRegistered" runat="server" Text="See Who Has Registered" CssClass="readmore" OnClientClick="listWindowOpen('<%# Eval(\"TripID\") %>');return false;" UseSubmitBehavior="False" /> 

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:AJ0718
ID: 40487553
Same problem.  I'm beginning to think this maybe isn't possible...
0
 
LVL 58

Expert Comment

by:Gary
ID: 40487568
Remove the runat="server"

 <asp:LinkButton ID="btnRegistered" Text="See Who Has Registered" CssClass="readmore" OnClientClick="listWindowOpen('<%# Eval("TripID") %>');return false;" UseSubmitBehavior="False" />

Open in new window

0
 

Accepted Solution

by:
AJ0718 earned 0 total points
ID: 40487892
Thanks for trying but it had to be a server control so I could bind the data.  You might be interested in how I finally solved it.  I had to make it a command button and then the command passes the argument and triggers the Javascript function in the code behind.
<asp:LinkButton ID="btnRegistered" runat="server" Text="See Who Has Registered" CssClass="readmore"
                                            CommandName="TripList" CommandArgument='<%# Eval("TripID") %>' />
0
 
LVL 58

Expert Comment

by:Gary
ID: 40487895
Ahh right, select your own answer as the comment
0
 

Author Closing Comment

by:AJ0718
ID: 40497777
This had to be a server control to bind the value. By making it a command button and writing the item command handler in the code behind, I could then register the script and it runs.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 110
Hybrid app to listen a radio 12 123
website content maintenance 3 96
AWS ELB 5 79
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

803 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