Posts Tagged ASP.NET

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

I have got the following error when I was developing a gridview editing on a webpage last week. This is most common issue, even I have faced several times earlier. But I want to keep this solution for beginners!

Here is the full error message:

"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"

error

My 1st suggestion is just check the cache! Meaning..clear your browser cache and refresh it and see whether it is working? if not continue with one of the following solutions!

1. Enable ViewState is false

Find the control which is giving problem in the page and then disable the ViewState! For me it was a  DropDownList so,

<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" EnableViewState="false">
</asp:DropDownList>
</EditItemTemplate>

2. Just place the data binding on the GridView events wherever you use the edit! For and example “RowCancelingEdit”

Protected Sub GridViewRelease_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles GridViewRelease.RowCancelingEdit
GridViewReleaseAnalyst.EditIndex = -1
BindData()
End Sub

That’s all, No more ViewState issue! Happy Programming!!

References:

  1. http://forums.asp.net/t/1368283.aspx/1
Advertisements

, , , , , , ,

1 Comment

Turn on detailed error messages in SharePoint 2007 /2010

This is not really new but currently I am working on some customized web parts, so I need to turn on/off the detailed error messages when I need to fix some hectic problems on my development environment. There are many posts regarding this, but I wanted to keep my own post for my future references. 😉

Normally SharePoint shows custom error messages to the users such as “An unexpected error has occurred” but this is not going to help, so we need to know the detailed ASP.NET error message to fix the problem. Here are the steps to turn off custom error messages.

Step 1: Go to the SharePoint host server and navigate to the Virtual Directories folder. Normally this is available in this path “C:\Inetpub\wwwroot\wss\VirtualDirectories”

Step 2: Find the web.config and get the backup for the safety purpose

Step 3: Open the web.config file using Visual Studio OR Notepad

Step 4: Find the “CallStack” and change the value to “true” instead of “false”

Step 5: Find the “CustomErrors” and change the value to “Off” instead of “On”

Step 6: Save and close the web.config, refresh the page then you will get the detailed (wired) error message. Time to fix this huh? 🙂

Error message before turning on:

Error message after turning on:

MSDN reference shows the “CustomErrors” values can be one of these:

Value Description
On Specifies that custom errors are enabled. The custom errors are shown to the remote clients and to the local host.
Off Specifies that custom errors are disabled. The detailed ASP.NET errors are shown to the remote clients and to the local host.
RemoteOnly Specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host.

If you want, you can also set the “CustomErrors” value to “RemoteOnly” to show custom errors only to the remote clients.

R./

References:

1. http://davidkvas.blogspot.com/2011/05/turning-on-detailed-error-messages-in.html

2. http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx

, , , , , , , ,

1 Comment