Thursday, October 22, 2009

Remove auto focus on SharePoint web form

We normally get auto focus if there is a textbox on the SharePoint web form. That works fine if the textbox is on the top of the web form, but if there is some content on the top and there is a textbox on the bottom of the page then it is a problem i.e since there will be auto focus on the textbox, when the page loads it will directly move the page to bottom to get the autofocus on the textbox. This happens because SharePoint automatically calls a JavaScript function named WebForm_AutoFocus(focusId) to get the auto focus on the textbox. This JavaScript function is present in the Core.js file. If you don’t want the textbox to get auto focus on the page load then simply override this function in your page, i.e simply call this function this way in your page…

function WebForm_AutoFocus(focusId)
{
//when the page loads, focus is automatically set to commets textbox, to remove the auto focus override this function.
//Override the AutoFocus function
}