Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including eval / bind values in OnClientClick code

I have a need to open a popup detail window from a gridview (VS 2005 / 2008). What I am trying to do is in the markup for my TemplateColumn have an asp:Button control, sort of like this:

<asp:Button ID="btnShowDetails" runat="server" CausesValidation="false"
   CommandName="Details" Text="Order Details" 
   onClientClick="window.open('PubsOrderDetails.aspx?OrderId=<%# Eval("order_id") %>',
   '','scrollbars=yes,resizable=yes, width=350, height=550');"   

Of course, what isn't working is the appending of the <%# Eval...%> section to set the query string variable.

Any suggestions? Or is there a far better way of achieving the same result?

like image 732
Ken Ray Avatar asked Sep 19 '08 14:09

Ken Ray


2 Answers

I believe the way to do it is

onClientClick=<%# string.Format("window.open('PubsOrderDetails.aspx?OrderId={0}',scrollbars=yes,resizable=yes, width=350, height=550);", Eval("order_id")) %>
like image 116
Tom Ritter Avatar answered Sep 21 '22 06:09

Tom Ritter


I like @AviewAnew's suggestion, though you can also just write that from the code-behind by wiring up and event to the grid views ItemDataBound event. You'd then use the FindControl method on the event args you get to grab a reference to your button, and set the onclick attribute to your window.open statement.

like image 25
bdukes Avatar answered Sep 22 '22 06:09

bdukes