Monday, May 31, 2010

Customizing Sharepoint List's NewForm.aspx "OK" button click

Requirement: In a share point list, while adding a new item, a field value has to be validated depending on other field value in the list.

Solution:

A) Create a new aspx page for customizing newform.aspx.
  1. Open Share point Designer and Open the site.
  2. Go to the Share point list which you want to customize.(Lists => )
  3. Select "NewForm.aspx" file and copy it.
  4. Paste it under the same location where "NewForm.aspx" file exists and rename it to "Customized_NewForm.aspx".
B) Customizing newform.aspx.
  1. Open the "Customized_NewForm.aspx" file in designer in design mode.
  2. Select the "ListFormWebPart" and delete it.
  3. From Insert menu, click on "Sharepoint Controls" and then click on "Custom List Form".
  4. It will prompt you to select the List and content type. Select your list and Content type(Item). Also select "New Item Form" radio button for "Type of the form to create". Click on "OK" button.
  5. It will insert your default new item page. You can do your customizations on this page such as removing some fields, hiding some fields, renaming the field text displayed etc.
C) Adding JavaScript code for customizing "OK" button click event.
  1. Open the "Customized_NewForm.aspx" file in designer in Code/Split mode.
  2. Go to the Content Place holder, "PlaceHolderMain" and insert the following lines of Javascript code and save the file.
script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("StartUpCustomScript");
function StartUpCustomScript() {
ChangeOkButtonOnclickEvent("Input","SaveItem");
}
function ChangeOkButtonOnclickEvent(tagName, identifier) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName); /*find all Input type controls on page (ie. control with tag )*/
for (var i=0; i < tempstring =" tags[i].name;" func =" tags[i].attributes[" onclick =" null;" approvaltype =" document.getElementById(" selectedapptype =" ApprovalType.options[ApprovalType.selectedIndex].value;" smapprovers =" document.getElementById(" selectedapptype ="="" value ="="">

C) Setting Customized New Form as default new item page
  1. Open the list where "Customized_NewForm.aspx" file exists in Sharepoint designer and open the properties.(Right click the file and click on "Properties...").
  2. From "List Properties" window, select "Supporting Files" Tab.
  3. Select "Item" for "content type specific forms".
  4. For "New item form", click on Browse and select the customized file i.e. "Customized_NewForm.aspx" and click on "Ok".
  5. Now try to open the new form from list. Notice the url change to "Customized_NewForm.aspx" instead of "NewForm.aspx".
  6. Click on "Ok" and save the settings.

Wednesday, May 26, 2010

Unrecognized configuration section 'connectionStrings'

When I try to create a virtual directory for web service in IIS and try to browse the .asmx file, igot the following error
"Unrecognized configuration section 'connectionStrings'".
This is happening because by default the ASP.Net version selected is "1.1.4322" where as the code i have written is .Net version 2.0.
So, the solution is change the Asp.net version.
Go to the virtual directory, Properties. From ASP.NET tab, select "2.0.50727" for ASP.Net Version and click ok. Now it should work properly.