0

To explain my situation... I am filling a listbox from a mysql table liek this

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim cmdtext = "SELECT * FROM avail_workouts"
    Using conn = New MySqlConnection(connString)
        Using cmd = New MySqlCommand(cmdtext, conn)
            conn.Open()
            reader = cmd.ExecuteReader()
            While reader.Read()
                ListBox1.Items.Add(reader("workout"))
            End While
        End Using
    End Using
End Sub

I then select one of the items on the listbox and click on a button (that will do something with the value selected from the listbox) that does nothing for now. That's when I get this error

Invalid postback or callback argument.  
Event validation is enabled using <pages enableEventValidation="true"/> 
in configuration or <%@ Page EnableEventValidation="true" %> 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.RegisterForEventValidation 
method in order to register the postback or callback data for validation.

I tried using

 EnableEventValidation="false"

This seemed to work, until I tried to use the selected value in the listbox. It seems to forget the value that is selected when I click on the button. So, how can I simply fill up a listbox, select a row in the listbox, and click a button where the selected value will be used without getting this error?

Thanks in advance!

Feign
  • 270
  • 10
  • 28

1 Answers1

0

include this lines...

 If Not IsPostBack
     //your code
  End If
The Hungry Dictator
  • 3,444
  • 5
  • 37
  • 53
  • Thanks, but this has no effect – Feign Oct 11 '13 at 05:15
  • EnableEventValidation="false" with this, and checking !page.ispostback, I get no error, but I can't use the selected value. Without EnableEventValidation="false", but still checking !page.ispostback, I get the error. – Feign Oct 11 '13 at 05:45
  • refer this link http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation.aspx – The Hungry Dictator Oct 11 '13 at 05:54
  • I tried both putting it in the single page and in the web.config. Same effect. – Feign Oct 11 '13 at 13:21