FormView and ObjectDataSource - Delete doesn't work

G

Guest

I am using a formview with an ObjectDatasource in ASP .Net 2.0. Everything
works fine until I try the delete. The ItemDeleting event fires, so I know
it should fire my delete method, but instead I get an error: No parameterless
constructor defined for this object, and the delete method is never called.

Anyone have any ideas?
 
G

Guest

I thought the stack trace may help on this

[MissingMethodException: No parameterless constructor defined for this
object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor,
Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
fillCache) +103
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean
skipVisibilityChecks, Boolean fillCache) +261
System.Activator.CreateInstance(Type type, Boolean nonPublic) +66

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +127

System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method) +38
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteDelete(IDictionary
keys, IDictionary oldValues) +1110
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary
oldValues, DataSourceViewOperationCallback callback) +75
System.Web.UI.WebControls.FormView.HandleDelete(String commandArg) +855
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +784
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs
e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source,
EventArgs e) +109
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String
eventArgument) +134

System.Web.UI.WebControls.LinkButton.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) +180
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
 
G

Guest

Without seeing some code, I cannot be 100% sure, but here is a hint that may
help you solve the issue:

The exception is stating you do not have a default constructor on an object,
so it cannot create the object in question without parameters, which are not
supplied in this context.

Step through your code and examine the call stack at the point the exception
is thrown. This will show the point of failure.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

First of all, thank you for replying.

I posted the stack trace in a reply to my original message. The problem is
that the error is being generating outside of my code. I have developed
another theory, but have not had the opportunity to test it. When I first
set this up, I got an error saying that the objectdatasource could not find a
method with the parameters oringal_Key, Key. My delete method originally
only took the Key as a parameter. I changed this and then got the default
constructor error. I am thinking that they key field may be setup as
read/write when it should be readonly or something to that effect.

Does that sound plausible?
 
G

Guest

Boy, now I feel like an idiot. My delete method was not shared, so the
objectdatasource was creating an instance of the object automatically. The
object class did not have a default constructor, so it generated an error.

I made the method shared and it works perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top