Click here to Skip to main content
11,433,220 members (57,462 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

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.
 
QuestionHey, DeathByChocolate Pin
Brisingr Aerowing21-Jan-13 14:58
memberBrisingr Aerowing21-Jan-13 14:58 
AnswerRe: Hey, DeathByChocolate Pin
Rob Graham21-Jan-13 15:14
memberRob Graham21-Jan-13 15:14 
AnswerRe: Hey, DeathByChocolate Pin
Bergholt Stuttley Johnson21-Jan-13 23:01
memberBergholt Stuttley Johnson21-Jan-13 23:01 
GeneralSigh.... Programming is fun. When it works. Pin
Brisingr Aerowing21-Jan-13 14:51
memberBrisingr Aerowing21-Jan-13 14:51 
GeneralForm factor and supported OS Pin
Mycroft Holmes21-Jan-13 14:32
memberMycroft Holmes21-Jan-13 14:32 
GeneralRe: Form factor and supported OS Pin
bwhittington22-Jan-13 2:25
memberbwhittington22-Jan-13 2:25 
GeneralRe: Form factor and supported OS Pin
Mycroft Holmes22-Jan-13 12:37
memberMycroft Holmes22-Jan-13 12:37 
GeneralBrilliant! Pin
DaveAuld21-Jan-13 10:03
mentorDaveAuld21-Jan-13 10:03 
GeneralRe: Brilliant! Pin
Jörgen Andersson21-Jan-13 11:36
memberJörgen Andersson21-Jan-13 11:36 
GeneralRe: Brilliant! Pin
Kyudos21-Jan-13 12:11
memberKyudos21-Jan-13 12:11 
GeneralRe: Brilliant! Pin
Deyan Georgiev21-Jan-13 13:47
memberDeyan Georgiev21-Jan-13 13:47 
GeneralRe: Brilliant! Pin
Mike Hankey21-Jan-13 17:01
memberMike Hankey21-Jan-13 17:01 
GeneralRe: Brilliant! Pin
Chris Quinn21-Jan-13 22:26
memberChris Quinn21-Jan-13 22:26 
GeneralAnother Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 9:44
protectorAspDotNetDev21-Jan-13 9: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 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 9:49
mentorDaveAuld21-Jan-13 9:49 
GeneralMessage Removed Pin
_beauw_21-Jan-13 10:05
member_beauw_21-Jan-13 10:05 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
DaveAuld21-Jan-13 10:07
mentorDaveAuld21-Jan-13 10:07 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Colin Mullikin21-Jan-13 11:16
memberColin Mullikin21-Jan-13 11:16 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 12:51
protectorAspDotNetDev21-Jan-13 12:51 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Brisingr Aerowing21-Jan-13 14:55
memberBrisingr Aerowing21-Jan-13 14:55 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Pete O'Hanlon21-Jan-13 10:53
protectorPete O'Hanlon21-Jan-13 10:53 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Colin Mullikin21-Jan-13 11:21
memberColin Mullikin21-Jan-13 11:21 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 12:49
protectorAspDotNetDev21-Jan-13 12:49 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
_Maxxx_21-Jan-13 11:01
member_Maxxx_21-Jan-13 11:01 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
AspDotNetDev21-Jan-13 12:52
protectorAspDotNetDev21-Jan-13 12:52 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
_Maxxx_21-Jan-13 14:18
member_Maxxx_21-Jan-13 14:18 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Jörgen Andersson21-Jan-13 11:06
memberJörgen Andersson21-Jan-13 11:06 
GeneralRe: Another Day Wasted By ASP.NET's Useless Error Messages Pin
Mark_Wallace22-Jan-13 2:44
memberMark_Wallace22-Jan-13 2:44 
GeneralMega Pile-Up Pin
Colin Mullikin21-Jan-13 9:19
memberColin Mullikin21-Jan-13 9:19 
GeneralRe: Mega Pile-Up Pin
DaveAuld21-Jan-13 9:53
mentorDaveAuld21-Jan-13 9:53 
GeneralRe: Mega Pile-Up Pin
Colin Mullikin21-Jan-13 10:01
memberColin Mullikin21-Jan-13 10:01 
GeneralRe: Mega Pile-Up Pin
SoMad21-Jan-13 10:26
memberSoMad21-Jan-13 10:26 
GeneralRe: Mega Pile-Up Pin
djj5521-Jan-13 10:45
memberdjj5521-Jan-13 10:45 
GeneralRe: Mega Pile-Up Pin
Wjousts21-Jan-13 11:40
memberWjousts21-Jan-13 11:40 
GeneralRe: Mega Pile-Up Pin
Albert Holguin21-Jan-13 11:21
memberAlbert Holguin21-Jan-13 11:21 
GeneralRe: Mega Pile-Up Pin
Colin Mullikin21-Jan-13 11:30
memberColin Mullikin21-Jan-13 11:30 
GeneralRe: Mega Pile-Up Pin
Wjousts21-Jan-13 11:42
memberWjousts21-Jan-13 11:42 
GeneralRe: Mega Pile-Up Pin
Colin Mullikin21-Jan-13 11:47
memberColin Mullikin21-Jan-13 11:47 
GeneralRe: Mega Pile-Up Pin
Wjousts21-Jan-13 11:54
memberWjousts21-Jan-13 11:54 
GeneralRe: Mega Pile-Up [modified] Pin
Colin Mullikin21-Jan-13 11:58
memberColin Mullikin21-Jan-13 11:58 
GeneralRe: Mega Pile-Up Pin
Wjousts21-Jan-13 15:33
memberWjousts21-Jan-13 15:33 
GeneralRe: Mega Pile-Up Pin
Colin Mullikin21-Jan-13 19:16
memberColin Mullikin21-Jan-13 19:16 
GeneralRe: Mega Pile-Up Pin
Albert Holguin21-Jan-13 12:47
memberAlbert Holguin21-Jan-13 12:47 
GeneralRe: Mega Pile-Up Pin
Nish Sivakumar21-Jan-13 12:16
sitebuilderNish Sivakumar21-Jan-13 12:16 
GeneralRe: Mega Pile-Up Pin
Nish Sivakumar21-Jan-13 12:19
sitebuilderNish Sivakumar21-Jan-13 12:19 
GeneralRe: Mega Pile-Up Pin
jeron121-Jan-13 12:55
memberjeron121-Jan-13 12:55 
GeneralCP Change? Pin
Kevin Marois21-Jan-13 9:12
memberKevin Marois21-Jan-13 9:12 
GeneralRe: CP Change? Pin
Collin Jasnoch21-Jan-13 9:16
memberCollin Jasnoch21-Jan-13 9:16 
GeneralRe: CP Change? Pin
Nish Sivakumar21-Jan-13 9:17
sitebuilderNish Sivakumar21-Jan-13 9:17 
GeneralRe: CP Change? Pin
jeron121-Jan-13 9:20
memberjeron121-Jan-13 9:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web04 | 2.8.150428.2 | Last Updated 5 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid