Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

repeater control causing Invalid postback or callback argument

Tags:

vb.net

I have read through many of the questions related to my situation but I have not found one that does. I currently have a repeater with 4 bound items to it, clicking on a button in the repeater causes my error, below is the markup and codebehind. Can someone explain to me why this is happening and the fix for it? (I have excluded the page decleration and just included the page_load event. let me know if i should cut and past full code in)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:Repeater ID="rptFoo" runat="server">
      <ItemTemplate>
        <asp:Button ID="btnfoo" runat="server" />
      </ItemTemplate>
    </asp:Repeater>
  </div>
  </form>
</body>
</html>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim items As New List(Of String)
items.Add("test1")
items.Add("test2")
items.Add("test3")
items.Add("test4")
rptFoo.DataSource = items
rptFoo.DataBind()
End Sub
like image 225
gh9 Avatar asked Jan 31 '11 18:01

gh9


2 Answers

"Invalid postback or callback argument" with Databound controls

answers my question incase anyone else needs this

like image 52
gh9 Avatar answered Nov 11 '22 20:11

gh9


That happens because the Repeater is getting datasource (binding) as you perform the item command operation. Just add if(not ispostback) to the page_load method.

like image 34
Adil Al-Hilali Avatar answered Nov 11 '22 18:11

Adil Al-Hilali