Craig Beamson
asked on
using an asp:button in repeater
I have a repeater as follows:
<asp:Repeater ID="rptResultItem" runat="server" OnItemCommand="Button_Clic k">
Within the temlpate of the repeater, I have multiple panels which have their visible property set according to some logic based on a databound value.
Withni each of these panels, I have the following asp:buttons:
<asp:Button Text="Add to basket" CommandArgument='<%#Contai ner.DataIt em("id") %>' CommandName="Add_To_Basket " runat="server" />
The sub below is a bit garbled - how do I need to rewrite it to get the ID value into the redirect string?
<asp:Repeater ID="rptResultItem" runat="server" OnItemCommand="Button_Clic
Within the temlpate of the repeater, I have multiple panels which have their visible property set according to some logic based on a databound value.
Withni each of these panels, I have the following asp:buttons:
<asp:Button Text="Add to basket" CommandArgument='<%#Contai
The sub below is a bit garbled - how do I need to rewrite it to get the ID value into the redirect string?
Sub Button_Click(ByVal s As Object, ByVal e As RepeaterCommandEventArgs)
Dim strRedirect As String
If e.CommandName = "Add_To_Basket" Then
strRedirect = "test.aspx?id=" & e.Item.Controls( 1).CommandArgument
Response.Redirect(strRedirect)
End If
End Sub
ASKER
I updated the sub to:
Sub Button_Click(ByVal s As Object, ByVal e As RepeaterCommandEventArgs)
Dim strRedirect As String
If e.CommandName = "Add_To_Basket" Then
strRedirect = "test.aspx?id=" & e.CommandArgument.ToString ()
Response.Redirect(strRedir ect)
End If
End Sub
but got the following error message:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="tru e"/> in configuration or <%@ Page EnableEventValidation="tru e" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.Regist erForEvent Validation method in order to register the postback or callback data for validation.
Sub Button_Click(ByVal s As Object, ByVal e As RepeaterCommandEventArgs)
Dim strRedirect As String
If e.CommandName = "Add_To_Basket" Then
strRedirect = "test.aspx?id=" & e.CommandArgument.ToString
Response.Redirect(strRedir
End If
End Sub
but got the following error message:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="tru
Try giving your button a name (ID="btnAddToBasket").
ASKER
Sorry Shaun - just got back from a week's holiday. Swamped today but will check this out and pick up this shortly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You should be able to do e.CommandArgument.ToString