Sunday, June 13, 2010

Problem With UpdatePanel and FormView

I got to this problem the other day which I thought is good to share it.

Situation 
In one of my ASP.NET application, I have a "Form View" which is bind to a database. For some reason, I needed to use Update Panel (Ajax) to implement click event without server post back. So I used it and it works fine but the problem was when I submit my Form View to save information, the controls that are inside of "Update Panel" would not updated on SQL database even though the update method called. 


Solution 
After a little bit of research, I found out that is bug with Update Panel and Form View but there is a work around. to fix it. All you need to do is to use "Updating" event of Form View and set the value of controls that are inside of "Update Panel" by using e.InputParameter[0] (Take a look at sample below. notice that we cast e.InputParameter[0] as the object of entity/class that bound to form view   and that solve the issue. here is some sample code :




        protected void odsMatterDetail_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
       
            //update items that are inside Update panel AJax. because of Update Panel items not bound back to form
            YesNoControl YesNoControlHST = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHST");
            YesNoControl YesNoControlIsCanadian = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlIsCanadian");
            YesNoControl YesNoControlIsCndLitigation = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlIsCndLitigation");
            YesNoControl YesNoControlHasLitigationCommence = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHasLitigationCommence");
            YesNoControl YesNoControlHasRealPropertyInCnd = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHasRealPropertyInCnd");




            LookupListBoxControl LookupListBoxOfficeProvince = (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxOfficeProvince");
            LookupListBoxControl LookupListBoxLitigationProvince = 
                                                              (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxLitigationProvince");
            LookupListBoxControl LookupListBoxRealPropProvince = 
                                                              (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxRealPropProvince");




            (e.InputParameters[0] as MatterDetail).IsGSTApplied = YesNoControlHST.Value;
            (e.InputParameters[0] as MatterDetail).IsCanadianClient = YesNoControlIsCanadian.Value;
            (e.InputParameters[0] as MatterDetail).ClientOfficeProvinceCode = LookupListBoxOfficeProvince.Value;
            
            (e.InputParameters[0] as MatterDetail).IsCanadianLitigationMatter = YesNoControlIsCndLitigation.Value;
            (e.InputParameters[0] as MatterDetail).HasLitigationCommenced = YesNoControlHasLitigationCommence.Value;
            (e.InputParameters[0] as MatterDetail).LitigationProvinceCode = LookupListBoxLitigationProvince.Value;




            (e.InputParameters[0] as MatterDetail).HasRealPropertyInCanada = YesNoControlHasRealPropertyInCnd.Value;
            (e.InputParameters[0] as MatterDetail).RealPropertyProvinceCode = LookupListBoxRealPropProvince.Value;




            (e.InputParameters[0] as MatterDetail).ModifBy = Security.CurrentUserID;
        }



Happy Coding 
:-0)

Tuesday, April 20, 2010

Issue with VSEWSS 1.3 when having interface in multiple assemblies

I got this post completely from John W Powell blog. I spent a lot of time to fix the issue I had with VSEWSS 1.3 and the solution was in his post. Thanks to John,



Visual Studio Extensions for Windows SharePoint Services (VSEWSS) Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

One error you may see when packaging solutions with VSEWSS is:  Microsoft.SharePoint.Tools.Utilities.VSeWSSServiceException VSeWSS Service Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.  Like most error messages from VSEWSS, there is not enough information provided to resolve the issue, so I hope to save you some time by providing a workaround that will permanently fix this problem.
When VSEWSS packages your solution, it uses reflection to enumerate the packaged assemblies.  It works fine until it encounters an assembly that implements an interface that is defined in another assembly as is often the case in the Microsoft.Practices.* assemblies.  I am unsure of exactly why, but the extensions are unable to resolve the dependent assemblies.  To work around the issue, you can copy the dependent assemblies to the GAC, but I don’t think this is the optimal solution and doing so will cause pain during development and debugging.  Another option is to copy the dependent assemblies to the VSEWSS service bin directory post build.  After trying this for awhile, and maintaining the script, I decided it would be much simpler to just copy all assemblies in my solution to the VSEWSS service bin directory on post build.  Here is the script:
@rem======================================================================
@rem
@rem    This script copies assemblies to the VSEWSS bin directory
@rem    to eliminate the packaging type load exception that occurs
@rem    when an interface is defined in a separate assembly.
@rem    
@rem    usage call $(ProjectDir)Scripts/CopyAssembliesToVSEWSSBin.bat $(TargetDir)
@rem
@rem======================================================================

@echo off

@echo ========== Locating VSEWSS bin directory ==========
@set vsewssbin=%programfiles%\Microsoft SharePoint Developer Tools 9.0\svc\bin
if not exist "%vsewssbin%" set vsewssbin=%ProgramW6432%\Microsoft SharePoint Developer Tools 9.0\svc\bin
@echo VSEWSS bin: %vsewssbin%

@echo ========== Copying assemblies to VSEWSS bin directory ==========
@xcopy "%1*.dll" "%vsewssbin%" /R /Y

To use the script, create a bat file in your project and call it from a post build event. It does take 64-bit installations into account, and it will also work on your Team Build server.

here is the link to original post

Issue with VSEWSS 1.3 when having interface in multiple assemblies

Happy Coding :)

Wednesday, January 13, 2010

The resource cannot be found.

Today I spent almost 4 hours to figure out why when I change my master page on my sharepoint site, I will get this error:

--------------------------------------------------------------

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /en/Pages/Home.aspx


Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

--------------------------------------------------------------------------------------

At first I thought the web part or resource files for languages are not deployed., Try to remove them and still couldn't find any clue. As I mentioned in one of my blogs, I turned off the friendly error messages hoping I got more detail about error but all I got was the above error :(

Thanks to MARC CHARMOIS for his article which finally gave me clue how to find missing resource. All you need to do is to go to "view source" of the page and look for "FileNotFoundException" and you will see what is missing :)

you can see Marc's full article here "Resolve Error : The resource cannot be found"

Happy Coding :-)

Tuesday, January 12, 2010

How to Turn User Friendly Error Message off in Sharepoint 2007 / MOSS





By Default SharePoint will not show the detail error message and rather just give a user friendly error message. (see picture )

As a developer though, you need to know the detail error log to be able to track it down. To turn off "User friendly Error Message" in SharePoint 2007 (MOSS) follow these steps:


  1. Open the web.config file for your site ( you can find it under inetpub folder e.g. C:\Inetpub\wwwroot\wss\VirtualDirectories )

  2. In the web.config file, search for the tag "CallStack=", locate the tag and change it from CallStack="false" to CallStack="true".

  3. In the web.config file, search for the tag and change "On" to "Off".

  4. Save the changes and close web.config.

  5. next time you test your page, you will see the actual error (see below)






Happy coding :)

How to Create a SharePoint Server 2007 Custom Master Page and Page Layouts for a Web Content Management Site

If you are doing SharePoint development, you are familiar with Site Branding and look and feel. I found the following article from Microsoft MSDN website which is a walk through branding and creating custom master page and custom layout (which are fundamental component of site branding in SharePoint/Moss environment). here is the link


I also find the following link useful. Thanks to Paul Culmsee

Start ...

Hello World !!!

I create this blog to share my knowledge of software development with other people out there. There are a lot of times I stock on something and after a lot of search in web and try and error I find a solution, but because I don't log it anywhere it will be forgotten after a few months. So I decided to create this blog to log my findings and solutions to problems I encountered and share it with others and hope it can be helpful for someone in future.

Paaya