[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

Pass Variable to Javascript from ASP.NET

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
AJ0718
Asked:
AJ0718
  • 4
  • 4
1 Solution
 
GaryCommented:
<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
 
AJ0718Author Commented:
Nope; same parser error.
0
 
GaryCommented:
<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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AJ0718Author Commented:
Same problem.  I'm beginning to think this maybe isn't possible...
0
 
GaryCommented:
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
 
AJ0718Author Commented:
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
 
GaryCommented:
Ahh right, select your own answer as the comment
0
 
AJ0718Author Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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