Solved

Pass Variable to Javascript from ASP.NET

Posted on 2014-12-08
8
131 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video/Image Streaming/Desktop Sharing 6 88
how to extract window origin in spring 2 75
website content maintenance 3 103
aws pricing 2 61
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

820 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