Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
On page load I get some images in datalist through sql table. I tried with the following code but get error like:
'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.'


XML
<asp:DataList ID="DataList1" runat="server"  OnItemCommand="Item_Command"  width="220" BorderStyle="None"    BorderWidth="2" RepeatColumns="2"    >
   <table id="Table3"  style=" margin-top:-33px" visible ="true">
   <tr>
   <td>
   <p >
  <asp:ImageButton ID="ImageButton1"  runat="server" CommandName="imgClick"  ImageUrl='<%#DataBinder.Eval(Container.DataItem,"PicturePath") %>' />
  <%--<img src= '<%#DataBinder.Eval(Container.DataItem,"PicturePath") %>' --%>
   <br /><br />



C#
public void Item_Command(Object sender, DataListCommandEventArgs e)

   {
       if (e.CommandName == "imgClick") // check commandname here
       {
       }
   }
Posted
Comments
creepz03 13-Dec-13 3:53am    
Does directly calling the onclick event of ImageButton does not work?
Karthik_Mahalingam 13-Dec-13 5:02am    
post your page directive tag

you can use model and modelless dialogue box

or


double click on imagebutton and whatever event generate just see there click event copy and paste in your condition

or

you can use parameter for this solution
 
Share this answer
 
 
Share this answer
 
Check Datalist Databinding with

If(!IsPostBack) 


This cause the postback event raised by a certain Image in the Datalist wont be in sync
since the Datalist control/item collection is regenerated through databinding.
Then the postback caused will be by an unknown source and throw the "EventValidation" Exception.
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 13-Dec-13 4:33am    
Well. I put the datalist binding under 'if(!IsPostBack)'. It works. Thank you.
JoCodes 13-Dec-13 4:46am    
Welcome Rajendran. Glad to hear your problem got solved.
VB
like:
'Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page

for this erroe use on page load
CSS
if(!ispostback)
{
//bind ur datalist here
}

and for click event write this code in aspimage button
HTML
onClick="ImageButton1_Click"

and at code behind
C#
protected void ImageButton1_Click(object sender , Eventargs e)
{
}
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 13-Dec-13 4:35am    
Fine.Thank you.
Omprakash Kukana 13-Dec-13 4:40am    
your welcom if it helps u you can mark it as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900