I can't figure out why I get this error. Yes, the error description should tell me but I don't understand it or how to resolve my situation so bare with me.First let me explain the code I have going on.
In my PageLoad I have registered this script to the page:
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "DeleteConfirmation", "function confirmDelete(){if(confirm('Are you sure you want to Delete?')){return true;}else {return false;}}", True)
Then, in my DataGrid, I have wired up each ImageButton (that's wrapped in an ItemTemplate in my GridView) to an onclick event that calls that JavaScript. I wired each button in each row in the ItemDataBound event of the GridView like this:
Dim btnDelete As ImageButton = CType(e.Item.FindControl("btnDelete"), ImageButton)
btnDelete.Attributes.Add("onclick", "confirmDelete();")
But when I click OK, or Cancel in the JavaScript Confirmation box, either or, I get this on the aspx page:
Exception Details: System.ArgumentException: 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.
Stack Trace:
[ArgumentException: 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.] System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +2127900 System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +106 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +32 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint |
![]() |
0 |
![]() |
Weird. Try this...
btnDelete.Attributes.Add("onclick", "if(!confirmDelete()) return false;")
Hope this helps! Please mark the helpful post(s) as Answer.
Josh Stodola ← Come check out my blog!
![]() |
1 |
![]() |
Far superior to put that function in an external file where as your need for further functions grows you can add to your file and your script is more readable. Also you can shorten that function considerably:-
function confirmDelete() {
return confirm('Are you sure you want to Delete?');
}This will still be callable in an external .js file just much easier to manage.
Personally I tend to go one further with this kind of thing. In my .js file I would have the following before the above function:-
runInitConfirms();
function runInitConfirms()
{
var oldOnload = window.onload;
if (typeof(window.onload) != "function") {
window.onload = InitConfirms;
} else {
window.onload = function()
{
oldOnload();
InitConfirms();
}
}
}
function InitConfirms() {
var inputs = document.getElementsByTagName("input");
for (i=0;i<inputs.length;i++) {
if (inputs[i].className.indexOf("confirmdelete")>-1) {
inputs[i].onclick = confirmDelete;
}
}
}Now I just need to give the image buttons a cssclass of "confirmdelete" and this function will be assigned to each of their onclick events. Just an alternative I like to throw out there.
As to the error itself I have come accross this before myself and would hold up my hand and say that I have sometimes set enableeventvalidation="false" in the @page declaration to avoid headaches.
Brian O'Connell (MCAD) - http://www.systemdotweb.com
![]() |
0 |
![]() |
Yea, I know about .js files. However this is a piece of *** application at a new company and we're just getting in here for a second to get something done for them and out. I'm not going to even begin cleaning this mess up when we're gonna be focused on a new portal coded the right way from scratch. Anyway yea, I agree with .js files however this is not my app and this is a new company but yes...gotcha.
I don't want to just make that false. There has to be a work around for this.
When is Microsoft going to get rid of VB.NET!
![]() |
0 |
![]() |
I was getting this error in aspx page. Only code i changed was I added following to page_load
if not ispostback then
.....
....
end if
and my page worked properly. I'm new to .net so cant analyse how this solved problem actually.
Please someone explain this work around.
![]() |
0 |
![]() |
I just tried that code with no problems except that you need to change btnDelete.Attributes.Add("onclick", "confirmDelete();") to btnDelete.Attributes.Add("onclick", "return confirmDelete();") to cancel the PostBack if the user presses the Cancel button.
NC...
![]() |
0 |
![]() |