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.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.ArgumentException: 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.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: 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.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +144
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +122
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
Version Information:
Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408
My source code(design)
<asp:Repeater ID="showallposts" runat="server"
onitemcommand="showallposts_ItemCommand"
onitemdatabound="showallposts_ItemDataBound">
<ItemTemplate>
<hr />
<div id="showpostername" style="color:Red;" >
<asp:Label ID="nameofposter" runat="server" Text='<%# Eval("FName") %>' style="font-size:medium;"></asp:Label>
</div>
<div id="showpost" style="background-color:Silver; color:Black; width:auto; height:auto; font-size:small">
<asp:Label ID="postcontent" runat="server" Text='<%# Eval("PostContent") %>'></asp:Label>
<asp:Label ID="postidis" runat="server" Text='<%# Eval("PostID") %>' Visible="false"></asp:Label>
</div>
<div id="textboxandbuttontocomment" style="height:auto;width:auto">
<asp:TextBox ID="commentonposttext" runat="server" TextMode="MultiLine" style="height:40px;width:500px"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="watermarkforaddcomment" runat="server" TargetControlID="commentonposttext" WatermarkText="Comment"></ajaxToolkit:TextBoxWatermarkExtender>
<br />
<asp:LinkButton ID="linkbutton_show_comments_specific" runat="server" Text="Show Comments" CommandName="showallcommentsofthispost" style="font-size:medium;color:Blue;width:20px;height:20px"></asp:LinkButton>
<asp:Button ID="submitcomment" runat="server" Text="Comment" CommandName="postcommentforthispost" style="left:300px;position:relative " />
</div>
<div id="repeaterinsiderepeater" style="height:auto;width:auto">
<asp:Repeater ID="Rerepeat" runat="server">
<ItemTemplate>
<div id="showcomments_specific" style="height:auto; width:auto">
<asp:Label ID="showspecificcommentslabeltext" runat="server" Text='<%# Eval("CommentContent") %>' style="font-size:small;color:Black;height:auto;width:auto"></asp:Label>
<asp:Label ID="commentpostid" runat="server" Text='<%# Eval("CommentID") %>' Visible="false"></asp:Label>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
My .cs code
protected void showallposts_ItemCommand(object source, RepeaterCommandEventArgs e)
{
Repeater childrepeater = (Repeater)e.Item.FindControl("Rerepeat");
Label nameofposter = (Label)e.Item.FindControl("nameofposter");
Label postcontent = (Label)e.Item.FindControl("postcontent");
Label postidis = (Label)e.Item.FindControl("postidis");
TextBox commentonposttext = (TextBox)e.Item.FindControl("commentonposttext");
LinkButton linkbutton_show_comments_specific = (LinkButton)e.Item.FindControl("linkbutton_show_comments_specific");
// linkbutton_show_comments_specific.OnClientClick += showcommentsbylink_Click(postidis);
Button submitcomment = (Button)e.Item.FindControl("submitcomment");
// submitcomment.OnClientClick += submitcomment_Click();
Label showspecificcommentslabeltext = (Label)e.Item.FindControl("showspecificcommentslabeltext");
selectedpostid = Convert.ToInt32(postidis.Text);
commentcontent = postcontent.Text;
if (e.CommandName == "postcommentforthispost")
{
submitcomment.OnClientClick += submitcomment_Click();
childrepeater.DataSource = ds;
childrepeater.DataBind();
commentonposttext.Text = "";
}
if (e.CommandName == "showallcommentsofthispost")
{
DataSet ds;
ds = bal.getallrelatedcomments(selectedpostid);
childrepeater.DataSource = ds;
childrepeater.DataBind();
}
}
public DataSet submitcomment_Click()
{
string commentdate = System.DateTime.Now.ToShortDateString();
string commenttime = System.DateTime.Now.ToShortTimeString();
int res = bal.savecomment(selectedpostid,Studid,commentcontent,commentdate,commenttime,firstname,lastname);
if (res > 0)
{
ds = bal.getallrelatedcomments(selectedpostid);
}
return ds;
}
If you your boss is breathing over your neck and you want to beat a deadline this will be the quick hot fix.
To fix the problem without compromising security ,you have to manually register your control for validation .Read this article here