Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Wednesday, August 28, 2013

Not able to add web parts to any page - page does nothing when clicking "Add Web Parts" is clicked

I faced a weird issue where I was not able to add any web parts to any page in the site. What weird is that Chrome works fine. It happens only in IE (all versions) and FireFox. On inspecting the bug I got an error when the page tries to get the web parts data back from the server asynchronously (you can view it in the console window/network traffic)

The error looked in FF console window some thing like this:

And the detailed Exception message was some thing like this:

[FormatException: Invalid character in a Base-64 string.]
   System.Convert.FromBase64String(String s) +0
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +98
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, 
String serializedState) +59
   System.Web.UI.HiddenFieldPageStatePersister.Load() +124

[ViewStateException: Invalid viewstate. 
...
...
[HttpException (0x80004005): The state information is invalid for this 
page 
and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String 
persistedState, String errorPageMessage, Boolean macValidationError) +148
   System.Web.UI.HiddenFieldPageStatePersister.Load() +10989814
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +11074728
   System.Web.UI.Page.LoadAllState() +46
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsy
ncPoint, Boolean includeStagesAfterAsyncPoint) +11070247
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPo
int, Boolean includeStagesAfterAsyncPoint) +11069786
   System.Web.UI.Page.ProcessRequest() +91
   System.Web.UI.Page.ProcessRequest(HttpContext context) +240
   ASP.LEFTRIGHTWIDEPAGELAYOUT_ASPX__745581150.ProcessRequest(HttpContext 
context) +9
   Microsoft.SharePoint.Publishing.TemplateRedirectionPage.ProcessRequest
(HttpContext context) +175

   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecu
tionStep.Execute() +599
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean
& completedSynchronously)


Did some research for almost a day and it turned out to be an issue that I introduced when fixing an issue with Chrome browser which did not load the SP.js file for all the clients. I inserted the below java script in all the page layouts which triggered twice in IE and FF which caused the issue.

The java script which introduced the bug is

if (typeof (_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();

the js function _spBodyOnLoadWrapper() got called twice and made the web parts panel to stop working.

I got this above javascript to fix some bugs in Chrome browser from the below site

http://developer.mintrus.com/2012/08/sharepoint-2010-improving-chrome-support/

But I made a mistake of just copying the the code to call just the function regardless of what browser it is. It made my day worse.

Be cautious to not to mess with all the JavaScript function of SharePoint. If you do make sure twice you are doing the right thing. Track any java script errors occur in any page before moving forward.

This I learnt the hard way. I still enjoy coding.

Happy Coding.
Senthil S

Thursday, April 25, 2013

Scrollbars not appearing in IE 7 with SharePoint 2010 sites

Finally, I had an issue with scrolling in SharePoint 2010 site pages and IE version 7 or lower. The Scroll bar appears for all the browsers but these scroll bars does appear in IE browsers version 7 and lower.

After a long research I found a great blog post talking about the same issue I was having. I implemented the changes and magically it started working for me.

http://kyleschaeffer.com/sharepoint/sharepoint-2010-scrolling/ 

Thanks
Senthil S

Tuesday, November 20, 2012

Resize SP Modal Popup (SP.UI.ModalDialog)

It has been a very long time since I posted a new blog post. I was working temporarily on MVC which is very exciting, interesting and hell lot to learn .....

Now coming to SP 2010, recently I had a requirement to re-size the modal popup dynamically based on the content on the page. As everyone know that we can set the width and height of the modal popup before opening the popup as below.

var options = {
    url: "/_layouts/useregistration.aspx",
    title: 'Login/Register',
    allowMaximize: true,
    showClose: true,
    autoSize: false,
    y: 50,
    width: 400,
    height: 600
};
var currentDialog = SP.UI.ModalDialog.showModalDialog(options);

The width and height parameters will be applied when the autoSize option is set to false. But I could not find any methods or options to re-size an already opened up popup using any functions. If the autoSize option is set to true, it re-sizes the window if the page gets posted back.

What happens when some dynamic content gets shown/hidden using css/jQuery? SP does not resize the popup based on this.

So I had to write a java script function to do that. I added the below function to a common JS file that is references in every page of my application to make use of it. Below is the function to re-size the popup which was opened up already.

this.Utility.resizeSPPopupWindow = function (width, height) {
    $(window.frameElement).parents('.ms-dlgContent').width(width);
    $(window.frameElement).parents('.ms-dlgContent').find('.ms-dlgBorder, .ms-dlgTitle').width(width);
    $(window.frameElement).width(width);
   
    try {
        var _intHeight = parseInt(height);
        height = _intHeight + 34; //34 is added to the height,the title bar's height adds up
    }
    catch (ex) {
    }


    $(window.frameElement).parents('.ms-dlgContent').height(height);
    $(window.frameElement).parents('.ms-dlgContent').find('.ms-dlgBorder').height(height);
    $(window.frameElement).height(height);
}

Of course it needs jQuery to work, it is one-way that I know of re-sizing already opened up modal popup.

If anyone out there knows any other way to achieve the same, I would love to know about it. Hope this helps some one.

UPDATE: If the popup modal is a new url, both the parent and the modal popup page should be from the same domain and should be using the same protocol (http or https).

Happy Coding !!!
Senthil S

Monday, April 2, 2012

Java script error when trying to change Page Layout

Recently, I faced a weird issue with SharePoint publishing pages and changing the layout of the page. I was able to add a new publishing page with different layouts in a pages library. But when I try to change the page layout of an existing page, I got a java script error in cui.debug.js. Just like the one below, I was not even be able to get the drop down with different page layouts to change


To fix this issue I had to debug the java script (CUI.debug.js) file in IE 8 or greater using the Developer tools. Once the exception occurred in the java script, traced the function calls using the "Call Stack" option and found a variable "$v_0.PopulationXML" and inspected the XML in VS and found the malformed XML.



After some research, I came to know that there was a orphaned page layout in the "Master Pages and Page Layouts" gallery. I was testing something else with page layout and content type relationships and left it there. But I removed the content type associated with the page layout.

After I deleted the particular page layout from the gallery, everything started to work fine.

Thanks
Senthil S