by Chad
3. February 2011 12:29
It is over a week late, but this post includes the sample code from my “Introduction to jQuery” presentation from the Springfield .NET Users group last week. The zip file in this post includes a Visual Studio 2010 Web Application that provides basic jQuery samples. The samples include manipulating the DOM, ajax, and jQuery UI. There is even a “try it” type page for experimenting with selectors and effects. Enjoy!
IntroductionToJQuery.zip (253.05 kb)
by Chad
11. June 2010 16:10
Can not call friend function on object which is not an instance of defining class
Google offered little help resolving this problem, so I thought I’d create this keyword-rich blog post so that someday it might climb the page ranks and help someone.
At work, we have an ASP.NET website that uses our Visual Basic 6 COM library via .NET Interops. Everything works quite well until you create a new .aspx page and forget to add the AspCompat=”true” @page directive attribute. It’s an easy thing to forget (it’s bitten me twice now.) The difficult part is that the COMException has an error message that is misleading: “Can not call friend function on object which is not an instance of defining class”.
AspCompat=”true”
The solution is actually very simple. The problem is caused because ASP.NET pages execute in a multithreaded apartment (MTA) and the VB6 COM Components expect to be in a single-threaded apartment (STA.) Adding the AspCompat=”true” attribute to the @page directive to force the page to execute in a STA.
The MSDN documentation does offer one word of caution about setting AspCompat=”true”. It can introduce performance issues if you instantiate your COM objects inside the page’s constructor. Microsoft recommends keeping that code in the page event handlers such as Page_Init and Page_Load.
6b93cd0d-0486-4781-89fa-92071ab99e4f|1|5.0
Tags:
ASP.NET | COM | Web
by Chad
2. March 2010 12:27
Recently, I was troubleshooting a difficult to find bug in an ASP.NET website. The bug was clearly environmental since the website worked for many other customers. We could only reproduce it on this particular customer’s server, so my diagnostic options were limited.
The Symptom
This application contains an ASP.NET DataGrid control that will redirect to a new page when a row is clicked. After some SQL and ASP.NET tracing, I determined that the server-side RowCommand event wasn’t firing.
The Cause
To enable selecting a row by clicking it, the original developer added some custom JavaScript that would invoke the Select row command on the datagrid when the row is clicked. ASP.NET uses dollar signs to delimit control namespaces so that controls can be uniquely named within the control hierarchy. When the HTML is rendered, ASP.NET replaces the delimiters with an underscore and uses that name for the element’s ID attribute. When forcing the post back, the original developer simply replaced the underscores with dollar signs so that ctl01_content_datagrid became ctl01$content$datagrid.
This works normally, however on this customer’s server clt01 was being named _ctl01, this broke the original developers assumption about names since the first underscore was actually part of the control name and not a delimiter. When the post back made it to the server, ASP.NET didn’t fire the server-side event because the names were wrong.
The Fix
The correct way to fix this would be to use the ClientScriptManager (via Page.ClientScript) to emit the correct __doPostPostBack(…) statement, but this particular application relies heavily on ASP.NET’s “normal” naming convention. The quick and simple solution was to add the <xhtmlConformance mode=”Transitional” /> element to the web.config. Since Transitional is the default mode for this setting, I assume (but didn’t verify) that the mode was set somewhere deeper in the configuration stack such as a root-level web.config or machine.config.
Details for this setting are here –> http://msdn.microsoft.com/en-us/library/ms228268.aspx