Today I ran into this error when posting back on my ASP.NET page.

System.Web.HttpUnhandledException (0x80004005): Exception of type ‘System.Web.HttpUnhandledException’ was thrown. —> 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.
at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)

It did not take me long to track down the problem. I forgot to add an ID to a dynamically created dropdownlist control.

 

Error:

An exception of type ‘System.MissingMethodException’ occurred in mscorlib.dll but was not handled in user code

Additional information: No parameterless constructor defined for this object.

 

Possible Solution:

If defining your gridview’s data source in the ASP.NET markup. Make sure the code behind’s constructor is public and has the right visibility.

In my case, Resharper suggested making the constructor protected, which this problem.

This method is a modified version of Mike Borozdin method which I happen to enjoy very much. The biggest changes I made where to add using statements around the disposable objects such as the Bitmap and the Graphics object to avoid memory leaks, as well as a few minor changes.

//Image Resize Helper Method
private static Bitmap ResizeImage(String filename, int maxWidth, int maxHeight)
{
    using (Image originalImage = Image.FromFile(filename))
    {
        //Caluate new Size
        int newWidth = originalImage.Width;
        int newHeight = originalImage.Height;
        double aspectRatio = (double)originalImage.Width / (double)originalImage.Height;

        if (aspectRatio <= 1 && originalImage.Width > maxWidth)
        {
            newWidth = maxWidth;
            newHeight = (int)Math.Round(newWidth / aspectRatio);
        }
        else if (aspectRatio > 1 && originalImage.Height > maxHeight)
        {
            newHeight = maxHeight;
            newWidth = (int)Math.Round(newHeight * aspectRatio);
        }

        Bitmap newImage = new Bitmap(newWidth, newHeight);

        using (Graphics g = Graphics.FromImage(newImage))
        {
            //--Quality Settings Adjust to fit your application
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);
            return newImage;
        }
    }
}