This is a migrated thread and some comments may be shown as answers.

Failed to load viewstate after closing radwindow

1 Answer 212 Views
Window
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Jul 2008, 04:20 PM
Hello,

   I am getting an error with the viewstate. I need to do some stuff in the code behind of the child radwindow prior to closing it. Then I need to do some other tasks on the parent form. After I click the close window of the child radwindow and then click the button on the parent form I get the 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. " I am new to this and have read the __doPostBack, but am not sure if I need that or where to start. I would appreciate any insight. I have supplied the code below. Thanks.

John

parentForm

aspx

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server">

<telerik:radscriptmanager id="ScriptManager1" runat="server" enabletheming="True"></telerik:radscriptmanager>

<div>

</div>

<telerik:radwindowmanager id="RadWindowManager1" runat="server" behavior="Default"

initialbehavior="None" left="" top=""></telerik:radwindowmanager>

<asp:Button ID="Button1" runat="server" Text="Button" />

</form>

</

body>

</

html>



code behind

Public

Partial Class frmMDI

Inherits System.Web.UI.Page

Dim newWindow1 As New Telerik.Web.UI.RadWindow()

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then

Try

'create child modal window

newWindow1.Behaviors = Telerik.Web.UI.WindowBehaviors.Move

newWindow1.Height =

"320"

newWindow1.Width =

"422"

newWindow1.Title =

"Child Window"

newWindow1.Modal =

True

newWindow1.VisibleTitlebar =

False

newWindow1.VisibleOnPageLoad =

True

newWindow1.NavigateUrl =

"frmChild.aspx"

newWindow1.Visible =

True

newWindow1.DestroyOnClose =

True

RadWindowManager1.Windows.Add(newWindow1)

Catch ex As Exception

Dim strEr As String = ex.ToString

End Try

Else

End If

End Sub

Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'do some code behind

Button1.Text =

"Refreshed"

End Sub

End

Class


child form

aspx

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Child Window</title>

<script type="text/javascript">

function get_RadWindow() //verify that it's a radWindow

{

var oWindow = null;

if (window.radWindow)

{ oWindow = window.radWindow; }

else if (window.frameElement.radWindow)

{ oWindow = window.frameElement.radWindow; }

return oWindow;

}

function JustClose()

{

get_RadWindow().Close();

}

</script>

</

head>

<

body>

<form id="form1" runat="server">

<telerik:RadScriptManager ID="ScriptManager1" runat="server" EnableTheming="True">

</telerik:RadScriptManager>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

</telerik:RadAjaxManager>

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="200px" Width="300px">

<asp:Button ID="Button1" runat="server" Text="Close Window" /></telerik:RadAjaxPanel>

</form>

</

body>

</

html>



code behind

Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'do some code behind

RadAjaxManager1.ResponseScripts.Add(

"JustClose()")

End Sub

1 Answer, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 24 Jul 2008, 03:08 PM
Hello John,

This behavior is expected - in the initial page load, you create a control, but after the postback this control does not exist. This raises the error - "The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request."

What I suggest in your case is to create the RadWindow in Page_Load and in your if/else statement to set only its VisibleOnPageLoad property accordingly to your logic:

Partial Class ViewStateProblem_Default 
    Inherits System.Web.UI.Page 
    Dim newWindow1 As New Telerik.Web.UI.RadWindow() 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
 
        newWindow1.Behaviors = Telerik.Web.UI.WindowBehaviors.Move 
        newWindow1.Height = "320" 
        newWindow1.Width = "422" 
        newWindow1.Title = "Child Window" 
        newWindow1.Modal = True 
        newWindow1.VisibleTitlebar = False 
 
        newWindow1.NavigateUrl = "frmChild.aspx" 
        newWindow1.Visible = True 
        newWindow1.DestroyOnClose = True 
        RadWindowManager1.Windows.Add(newWindow1) 
 
        If Not IsPostBack Then 
 
            Try 
 
                'create child modal window 
 
                newWindow1.VisibleOnPageLoad = True 
            Catch ex As Exception 
                Dim strEr As String = ex.ToString 
            End Try 
        Else 
            newWindow1.VisibleOnPageLoad = False 
        End If 
    End Sub 
    Protected Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
 
        'do some code behind 
 
        Button1.Text = "Refreshed" 
 
    End Sub 
End Class 



Regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
John
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Share this question
or