2

Im trying to add a button in my grid view that will redirect me to another page and pass the id of the movie. This is my code

<asp:Button ID="Button1" runat="server" CausesValidation="False" 
                     PostBackUrl="~/Add/CheckMovie.aspx?movie=<%#Eval("mov_id")%>" 
                />

A while back in a different app I used similar code and it worked fine

<a href="editUser.aspx?usr=<%# Eval("usr") %>"><%# Eval("usr") %></a>

Is it because Im using a different tag, or maybe because of the url ?

Chris Nickson
  • 105
  • 2
  • 3
  • 8
  • 1
    I'm pretty confident its because you're using the <%#%> tags in an ASP control (asp:Button). Use a HTML button instead - let me just double check something i wrote the other week. Had a similar issue. – tutts Feb 23 '12 at 15:30

3 Answers3

2
PostBackUrl='<%# "~/Add/CheckMovie.aspx?movie=" + Eval("mov_id") %>'
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
1

Depending on how you get the value of mov_id you may be better adding the code to the page_load method, something like this

HTML

<asp:Button ID="Button1" runat="server" CausesValidation="False" PostBackUrl="" />

Code Behind

Button1.PostBackUrl = "~/Add/CheckMovie.aspx?movie=" + mov_id;
Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
1

as mentioned in the comment above, its because of the server tag inside the ASp:Button control. You can change it to a HTML button like so:

<button class="button" id="submitreorder" onclick="parent.location='<%=ResolveUrl("~/order/ShoppingCart") %>/delete/<%# Eval("Item_ID") %>'">Remove</button>
tutts
  • 2,373
  • 2
  • 20
  • 24