Reputation: 577
Button in the page does not work after the page is executed. the function of this button is to retrieve the images from the paths provided. the use of isPostBack is important here but am not getting where to use it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class pictures : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/Images/10003253_697566723628663_1903222345_n.jpg";
Image2.ImageUrl = "~/Images/1503929_10152290013211351_1280973165_n.jpg";
Image3.ImageUrl = "~/Images/1558538_697566540295348_743334414_n.jpg";
}
}
when the page is loaded and i click the button then this error message is provided:
Server Error in '/' Application.
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. "
The aspx code is:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pictures.aspx.cs" Inherits="pictures" MasterPageFile="~/MasterPage.master"%>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Image ID="Image1" runat="server" Height="200px" />
<asp:Image ID="Image2" runat="server" Height="200px" />
<asp:Image ID="Image3" runat="server" Height="200px" /><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" is/>
</asp:Content>
Upvotes: 0
Views: 275
Reputation: 413
The Webcontrol "Content" is a particular one:
it's for replacing controls in a masterpage placeholder.
you can check the msdn:
http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.content(v=vs.110).aspx
and this SO post contains some more details:
Content control not accessbile from content page?
can you temporarily delete the <asp:Content></asp:Content>
markup to see if the problem persists?
For consistency and security reasons, it's better not to change the default EnableEventValidation
property value if you can avoid it.
Upvotes: 0
Reputation: 1750
in your aspx file you should put the first line as this :
<%@ Page EnableEventValidation="false" %>
If you already have something like <%@ Page so just add the rest => EnableEventValidation="false" %>
Web.Config:
<pages enableEventValidation="false"/>
It help to work for all pages in aspx.
Upvotes: 0
Reputation: 10285
The reason for it is that the Data is posted back to the sever contains some client side scripting code(mostly Javascripts), and this will lead to some kind of security preach, so by default, the enableEventValidation
is set to true.
For Particular Page You can set it as
<%@ Page EnableEventValidation="false" %>
or in Web.Config you can use
<pages enableEventValidation="false"/> //for all pages
Same Questions
asp.net: Invalid postback or callback argument
Upvotes: 1