Click here to Skip to main content
13,004,203 members (75,785 online)

Welcome to the Lounge

   

For discussing anything related to a software developer's life. Technical discussions are encouraged, but click here to ask your programming questions.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: Form factor and supported OS Pin
Mycroft Holmes22-Jan-13 11:37
memberMycroft Holmes22-Jan-13 11:37 
GeneralBrilliant! Pin
DaveAuld21-Jan-13 9:03
mentorDaveAuld21-Jan-13 9:03 
GeneralRe: Brilliant! Pin
Jörgen Andersson21-Jan-13 10:36
memberJörgen Andersson21-Jan-13 10:36 
GeneralRe: Brilliant! Pin
Kyudos21-Jan-13 11:11
memberKyudos21-Jan-13 11:11 
GeneralRe: Brilliant! Pin
Deyan Georgiev21-Jan-13 12:47
memberDeyan Georgiev21-Jan-13 12:47 
GeneralRe: Brilliant! Pin
Mike Hankey21-Jan-13 16:01
memberMike Hankey21-Jan-13 16:01 
GeneralRe: Brilliant! Pin
Chris Quinn21-Jan-13 21:26
memberChris Quinn21-Jan-13 21:26 
GeneralAnother Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 8:44
protectorAspDotNetDev21-Jan-13 8:44 
Try running this code in an ASPX page (and click the button once the page loads):
<%@ Page Language="vb" AutoEventWireup="false" %>
 
<script runat="server">
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    lvTest.DataSource = New List(Of String)() From {"hello"}
    lvTest.DataBind()
  End Sub
 
  Protected Sub btnTest_Click(sender As Object, e As System.EventArgs)
    lblTest.Text = DateTime.Now.ToString()
  End Sub
</script>
 
<!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>Testing Postback Error</title>
</head>
<body>
    <form id="frmMain" runat="server">
      <div>
        <asp:Repeater runat="server" ID="lvTest">
          <ItemTemplate>
            <asp:Button runat="server" ID="btnTest" Text="Test Postback" onclick="btnTest_Click" />
          </ItemTemplate>
        </asp:Repeater>
        <asp:Label runat="server" ID="lblTest" />
      </div>
    </form>
</body>
</html>


You'll get an informative and useful error message like this:
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.


Everywhere I searched online suggested I add EnableEventValidation="false" to the page declaration, which is really just covering up the problem. I eventually discovered the real fix:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If Not Page.IsPostBack Then
    lvTest.DataSource = New List(Of String)() From {"hello"}
    lvTest.DataBind()
  End If
End Sub


It seems that binding on a postback in the page load (before the click handlers are called) confuses ASP.NET (I suppose because the control posting back gets replaced when binding occurs). The fix is to not do that. If I had more motivation, I'd go through all those online posts and show them the actual fix. Roll eyes | :rolleyes:

JokeRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
DaveAuld21-Jan-13 8:49
mentorDaveAuld21-Jan-13 8:49 
GeneralMessage Removed Pin
_beauw_21-Jan-13 9:05
member_beauw_21-Jan-13 9:05 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
DaveAuld21-Jan-13 9:07
mentorDaveAuld21-Jan-13 9:07 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Colin Mullikin21-Jan-13 10:16
memberColin Mullikin21-Jan-13 10:16 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 11:51
protectorAspDotNetDev21-Jan-13 11:51 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Brisingr Aerowing21-Jan-13 13:55
memberBrisingr Aerowing21-Jan-13 13:55 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Pete O'Hanlon21-Jan-13 9:53
protectorPete O'Hanlon21-Jan-13 9:53 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Colin Mullikin21-Jan-13 10:21
memberColin Mullikin21-Jan-13 10:21 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 11:49
protectorAspDotNetDev21-Jan-13 11:49 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
_Maxxx_21-Jan-13 10:01
member_Maxxx_21-Jan-13 10:01 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 11:52
protectorAspDotNetDev21-Jan-13 11:52 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
_Maxxx_21-Jan-13 13:18
member_Maxxx_21-Jan-13 13:18 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Jörgen Andersson21-Jan-13 10:06
memberJörgen Andersson21-Jan-13 10:06 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Mark_Wallace22-Jan-13 1:44
memberMark_Wallace22-Jan-13 1:44 
GeneralMega Pile-Up Pin
Colin Mullikin21-Jan-13 8:19
memberColin Mullikin21-Jan-13 8:19 
GeneralRe: Mega Pile-Up Pin
DaveAuld21-Jan-13 8:53
mentorDaveAuld21-Jan-13 8:53 
GeneralRe: Mega Pile-Up Pin
Colin Mullikin21-Jan-13 9:01
memberColin Mullikin21-Jan-13 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 27 Jun 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid