Dropdownlist problem med postback og databind
Hej Eksperter.Jeg har følgende kode:
***************** default.aspx *****************
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" EnableEventValidation="True" %>
<!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:label ID="Label1" runat="server" Text="Label"></asp:label>
<br />
<br />
<br />
<br />
<asp:dropdownlist ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="test">
</asp:dropdownlist>
<br />
</div>
</form>
</body>
</html>
***************** default.aspx.cs *****************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList AL = new ArrayList();
// Tilføj indhold
AL.Add(" 0999 København C (DR-Byen) ");
AL.Add(" 1000-1499 København K ");
AL.Add(" 1500-1799 København V ");
//Bind data til controls
DropDownList1.DataSource = AL;
DropDownList1.DataBind();
}
}
protected void test(object sender, EventArgs e)
{
Label1.Text = "test";
}
}
}
Mit problem er når jeg så vælger en ny værdi i dropdownlisten får jeg denne fejl:
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.
Hvilket jeg har gjort, som i kan se i koden.
Håber i kan hjælpe!
Mvh
Martin