There was an error in this gadget

Search This Blog

Thursday, December 22, 2011

Failed To Load Viewstate

Once I encountered the following error

Failed to load viewstate.

The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.

For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request

I searched a lot on google and finally i found one solution.

Here is the reason why the error happens:

If a control is added dynamically to a placeholder say (UserControl1.ascx) and the control's viewstate is enabled ,thenafter on the next postback a different control is added say (UserControl2.ascx) to the placeholder.

when try to load the viewstate of the control contained at the placeholder it's expecting the previous control  u added :(UserControl1.ascx) but it will encounter another control instead  (UserControl2.ascx) in the place of the first control SO IT WILL FAIL.

Viewstate of the control tree in the placeholder child controls is saved by index not by key so even if we give our ascx control as a key before adding it to the placeholder we will get the same error.


Just disable viewstate of the usercontrol.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" abc.aspx.cs" Inherits="#####"  EnableViewState="false"%>

20% OFF + FREE Set-up on select items! Online Exclusive for New Customers Only.

Saturday, October 1, 2011

Maintain tabs in SpryTabbedPanels

This post helps you to maintain the tab index of spry tabpanal at every post back event

I have done small changes in SpryTabbedPanels.js for this post back purpose

You can download the upgraded version of SpryTabbedPanels.js at

To use this script follow the steps

Steps to be followed to implement spreyTabbedpanels

Save on Snacks and Party Favorite Foods

Friday, February 11, 2011

Delete file which is already in use using

Sometime scenario arises where we need to delete a file using C#.
But sometime an error is thrown like "File is already in use. Not able to delete"

Here is the solution to delete that file

       FileInfo f = new FileInfo(FullFileName);

Wednesday, January 5, 2011

Days gap between two dates in ORACLE

To find out days gap between two dates excluding business holidays in oracle use following query.

SELECT count(dt) FROM
(SELECT TO_DATE(StartDate) + level - 1 dt FROM dual CONNECT BY level <=(TO_DATE(EndDate)-TO_DATE(StartDate)))
where to_char (dt,'D')<>1

Below written query is the example of it.

This query returns days count between 30-nov-2010 and 12-dec-2010 excluding Sundays
(1 for sunday,2 for monday and so on......)

SELECT count(dt) FROM
(SELECT TO_DATE('30-nov-2010') + level - 1 dt FROM dual CONNECT BY level <=(TO_DATE('12-Dec-2010')-TO_DATE('30-nov-2010')))
where to_char (dt,'D')<>1 

To find out dates between two dates use following query

SELECT to_char(dt,'dd/MM/yyyy') as date FROM
(SELECT TO_DATE(StartDate) + level - 1 dt FROM dual CONNECT BY level <=(TO_DATE(EndDate)-TO_DATE(StartDate)))
where to_char (dt,'D')<>1

Happy coding.