Listed below is the definition of my function (vb).
I am trying to check the value of a checkbox inside the function. I am currently unable to do this without getting an error stating that
"Error 305: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class."
Is there anything I can change so that I can get the value to see that if a checkbox is checked or not? The method must be shared, so it works with the existing javascript and the use of pagemethods
Thanks
<System.Web.Services.WebMethod()> _
Public Shared Function Load(inputs here - taken out for stack overflow) As String
edit- the only other solution i can think of is to find a way for the page's javascript onload to run before the server side, this would solve my issue as well if anyone knows how this can be done.
Yes. Do what the message suggests and make the method non-shared, then you'll be able to access the members of the page.
Related
I have an MS ReportViewer report that is bound to a datasource, that is requesting a property that it shouldnt. I have checked all of the fields on the report and I cant find anywhere its used.
Putting a break point on the property shows its definately being called, but I cant find out from where as its the ReportViewer is making the call.
****Is there a way to find out where this property is being called from?**
Here is what I have checked so far:
Stack Trace: shows managed code, checked the disassembly but couldn't see anything obvious.
Call hierarchy shows all the places that property is called from - none of which are on the report.
Update:
Tried n8wrl's suggestion of throwing an exception, but the stack is still on unmanaged code.
Update 2
I have also tried adding Xml and Script ignore tags in case the object as being serialized somewhere but that didn't work (unless they are not the correct tags to ignore serialization?)
Ok, I have come up with a solution. I assumed this had something to do with serialization so I passed the datasource in to a System.Web.Script.Serialization.JavaScriptSerializer.
When serializing the object I found all of the properties that were causing the code to bomb out. I added [ScriptIgnore] tags to these properties to stop them begin serialized as they were not used.
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
serializer.RecursionLimit = int.MaxValue;
object o = serializer.Serialize(base.CurrentOrder);
In my SharePoint code, I have the following line:
SPWeb web = site.RootWeb; //site is an SPSite object
When I rebuild my project and run the SPDispose tool on the assembly, I get the following error:
Module: Blah.SharePoint.Features.Core.dll Method:
Blah.SharePoint.Features.Core.Helpers.FeatureDeploymentHelper.RemoveWebPartFiles(Microsoft.SharePoint.SPFeatureReceiverProperties,System.String)
Statement: web := site.{Microsoft.SharePoint.SPSite}get_RootWeb()
Source:
C:\xxx\xxx\Main\Source\SharePoint\Features\Core\Helpers\FeatureDeploymentHelper.cs
Line: 26
Notes: Disposable type not disposed: Microsoft.SharePoint.SPWeb
***This may be a false positive depending on how the type was created or if it is disposed outside the current scope More Information:
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140
What I want to do is to have the SPDispose tool ignore this error, so I have pulled the SPDisposeCheckIgnore class and supporting enum into my project, and I've decorated my method appropriately:
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed.")]
public static void RemoveWebPartFiles(SPFeatureReceiverProperties properties, string assemblyName)
{
...
}
After doing all of this, I still receive the error. Anyone know how I might go about getting rid of that error?
Two things need to be done here.
1) The SPDisposeCheckIgnore class must be defined in the SPDisposeCheck namespace. You CANNOT have your own namespace. See the related comment on this page: http://archive.msdn.microsoft.com/SPDisposeCheck/
2) Anything you are trying to ignore within RunWithElevatedPrivleges must be pulled into an external method or it will not be recognized. This was not being done in the example above, but was being done in other places.
These two rules must be followed for ignore to work. Hope this helps someone else down the road.
Double check how you're retrieving and assigning the RootWeb object. If it's done in an external method, the DisposeChecker might not pick up that it's a RootWeb reference.
I don't see anything wrong with what you've written. I pulled out getting the root web into a static method so I only had to ignore this error in one place, and it works in anonymous delegates. The following worked for me:
public class DisposeUtils
{
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed. http://blogs.msdn.com/b/rogerla/archive/2009/11/30/sharepoint-2007-2010-do-not-dispose-guidance-spdisposecheck.aspx")]
public static SPWeb GetRootWeb(SPSite site)
{
return site.RootWeb;
}
}
Sorry, I'm not sure if that helps exactly - I'm saying your code should work. Have you checked SPDisposeCheck to see how it handles 'Documented' and 'Undocumented' errors? (I've never been entirely clear what those settings do)
I have followed this tutorial for the most part to explain what I am doing. http://www.asp.net/data-access/tutorials/creating-a-business-logic-layer-vb
What i need to do is figure out the best way to approach to be able to update my formview. I do not understand what the tutorial is trying to explain to me so i tried it the way i have updated a gridview before. But I am receiving "No parameterless constructor defined for this object." I tried to debug and view the callstack but it does not really tell me much.
I have my sql stored procedure to update which when executed works fine.
I also have another class in which i reference the application details class
applicant.vb
This is the code in order for when you click the view details link on the gridview it passes you off to another page that shows that applicants details it is within the same applicant.vb class
I am trying to update using the following method on the .aspx page but i receive the following error "No parameterless constructor defined for this object."
Memberdetails.aspx
Without knowing which line of code is causing that error, I can't say for sure, however, my guess is that your error is on this line of code.
_applicantadapter = New applicantTableAdapter
Put an open parentheses after applicantTableAdapter to see the different constructor signatures available to you for that type. I bet you'll see none of the options allow no parameters.
That error means that the object type you are trying to instantiate requires that you include parameter(s) (and you are not).
I have an ObjectDataSource on a page that is producing the error "Object does not match target type" when its Insert method is invoked. From Googling this message, I believe this the message is deceptive and I'm actually getting a null reference error on the object that the ObjectDataSource is trying to invoke the method on, but I'm darned if I can figure out why.
<asp:ObjectDataSource ID="dsAddComment" runat="server"
DataObjectTypeName="BookCatalogue.InteractionDocuments.UserComment"
SelectMethod="GetNewComment" TypeName="BookCatalogue.AddCommentPresenter"
InsertMethod="AddComment" OnObjectCreating="dsAddComment_ObjectCreating" />
The Type that is being called upon Insert is an AddCommentPresenter. The method AddComment is not static. If I change this to static, I don't get the error and the method is found without problem. When it's not static, the error occurs. That's whyI htink that the underlying problem is that somehow I'm not getting a valid instance of my Presenter class when the AddComment method is invoked.
My AddCommentPresenter class doesn't have a parameterless constructor. This will cause an error normally. To get around it I'm overriding the ObjectCreating event in my page's code-behind and assigning an instance of the Presenter class.
protected void dsAddComment_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
e.ObjectInstance = presenter;
}
I can step through my ObjectCreating method and it is a valid, non-null Presenter instance that's being passed into the e.ObjectInstance property.
My AddComment method has the correct signature.
public void AddComment(UserComment newComment)
{
...
}
I've also checked the obvious things, like misspelling the type name on the aspx page, but all is correct there.
Anyone have any ideas? I must say that I find the ObjectDataSource class very difficult to work with....
A colleague found the cause of my problem. The AddCommentPresenter class in my web app was defined in the website's App_Code directory. For some reason, that was causing the error. Move it out of there, into the main directory of the website and the code worked. I can't find any mention in any ObjectDataSource documentation of this being a potential gotcha for the control, but there you go.
I've also been told that it should be possible to keep the class in the App_Code folder, but include the syntax ",__code" at the end of the TypeName. E.g.
TypeName="MyNamespace.MyType,__code"
but personally, I didn't get that working when I tried it. Another post to an ASP.Net forum suggested changing the TypeName to
TypeName="_MyNamespace.MyType"
That didn't work for me, either. I ended up just pulling the class out of the App_Code folder.
I am using methods with the Attribute [WebMethod] in my aspx pages. I don't use any asp.net ajax but jQuery to call these methods and return objects in JSON. This all works fine.
Next I added an authorization check inside the webMethod, if the current user doesn't have access to the feature I need to let the calling JavaScript know.
So I am throwing an AccessViolationException exception which can then be parsed by the OnError callback function in JavaScript. This works too but the exception includes the full StackTrace and I don't want to make this available to the calling client.
What other ways I could use to return an "Access Denied" to the client when the WebMethod returns a business object?
I'm using ASP.Net 3.5SP1 and jQuery 1.32
You can also add a:
customErrors mode="On"/
in your web.config, this will cut away the stack trace and leave you only the exception message
Why propagate errors through the wire? why not use an error response ?
Just wrap your object in a response object wich can contain an error code for status and an error message to present to users.
As suggested by NunFur I changed my approach and rather than throwing an error, I return a 'richer' object.
There are at least two options, the first one would be to encapsulate my business object into a response object with some status properties. I tried this but it makes the JSON more complicated.
So rather than adding a new object I added two properties to my business object, something like ServiceStatus and ServiceMessage. By default these are 200 and '', but can be set by the WebMethod code if anything goes wrong (no access, proper error). In this case they business object will be 'empty' (no data). The JavaScript code then first checks for the ServiceStatus and reacts appropriately.
I add the two fields to all my objects that are returned by WebMethods, even a simple string. They have to implement an Interface with those two properties.
Now I have complete control over that goes over the wire in case something unexpected is happening.
Thanks for the input
I save exceptions for when things go really wrong. (e.g. can't connect to the database)
Either return nothing (null/nill/whatever), or return a false bool value.
Sorry that I don't have a better answer than that...I'll have to keep looking myself.
You could look at SoapException: http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapexception(VS.71).aspx
I'm just not sure, if it will work when it is called from JavaScript. Espeially if it's called with a get-request.
BTW AccessViolationException is to my best knowlegde ment to be thrown when the application is accessing memory it has no access to.
/Asger