This is a migrated thread and some comments may be shown as answers.
Ajax-ified web part works with tree. Viewstate Error when radTextbox added to updatepanel
1 Answer 30 Views
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 30 Sep 2008, 02:33 PM
My web part works as expected, but if I add a radTextbox after the tree instead of a standard web textbox control, AJAX no longer works, instead generating an "... Invalid Viewstate error"

Here's my code that adds contrlos, called from :

' objects available to be updated via ajax

Private _timeLabel As Label

Private _txtUserid As New TextBox   ' If I change this to RadTextBox, viewstate errors occur.

Private _statusLabel As Label

Private m_RadTreeFolderHierarchy As New Telerik.Web.UI.RadTreeView

 

Public Sub New()

Me.ExportMode = WebPartExportMode.All

GetUserInfoFromWSS()

 

End Sub

 

Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)

MyBase.OnInit(e)

Page.ClientScript.RegisterStartupScript(

GetType(_TreeNav_Webpart), Me.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", True)

If Me.Page.Form IsNot Nothing Then

Dim formOnSubmitAtt As String = Me.Page.Form.Attributes("onsubmit")

If Not String.IsNullOrEmpty(formOnSubmitAtt) AndAlso formOnSubmitAtt = "return _spFormOnSubmitWrapper();" Then

Me.Page.Form.Attributes("onsubmit") = "_spFormOnSubmitWrapper();"

End If

' Check for a scriptmanager, if none, add one.

Dim scriptManager As ScriptManager = Web.UI.ScriptManager.GetCurrent(Me.Page)

If scriptManager Is Nothing Then

scriptManager =

New RadScriptManager()

Me.Page.Form.Controls.AddAt(0, scriptManager)

End If

 

End If

End Sub

Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs)

MyBase.OnLoad(e)

AddControls()

End Sub


Protected

Sub AddControls()

Dim

nl As String = Environment.NewLine

Dim msgTxt As String = ""

Dim wrapPanel As New Panel()

wrapPanel.ID =

"Panel1"

Me.Controls.Add(wrapPanel)

Dim lblUserId As New Web.UI.WebControls.Label

lblUserId.Text =

"UID: " + _AttorneyID

lblUserId.ToolTip = _WorkEmail

wrapPanel.Controls.Add(lblUserId)

 

 

m_RadTreeFolderHierarchy.ID = "

NavTree" ' this name is referenced in client side javascript

'_txtUserid.Text = Environment.UserName

Try

' see if TreeData" & _AttorneyID & ".xml" exists to use. If not, use the default tree.

'If IO.File.Exists("~/MJComponentSupport/TreeData_" & _AttorneyID & ".xml") Then

Try

m_RadTreeFolderHierarchy.LoadContentFile(

"~/TreeSupport/Userdata/TreeData_" & Environment.UserName & ".xml")

msgTxt = Environment.UserName &

"'s Tree Loaded"

Catch ex As Exception

 

msgTxt =

"Default Tree Loaded"

m_RadTreeFolderHierarchy.LoadContentFile(

"~/TreeSupport/Userdata/TreeData.xml")

End Try

' change some visual display options

m_RadTreeFolderHierarchy.EnableTheming =

True 'similar to tree item

m_RadTreeFolderHierarchy.EnableAjaxSkinRendering =

True

m_RadTreeFolderHierarchy.Skin = _RadSkin

m_RadTreeFolderHierarchy.AllowNodeEditing =

False

m_RadTreeFolderHierarchy.CheckBoxes =

True

m_RadTreeFolderHierarchy.EnableDragAndDrop =

True

AddHandler m_RadTreeFolderHierarchy.NodeDrop, AddressOf treeView_NodeDrop

AddHandler m_RadTreeFolderHierarchy.NodeClick, AddressOf treeView_NodeClick

AddHandler m_RadTreeFolderHierarchy.ContextMenuItemClick, AddressOf treeViewMenu_ItemClick 'ContextMenuItemClick

AddHandler m_RadTreeFolderHierarchy.NodeEdit, AddressOf treeView_NodeTextChanged

'AddHandler m_RadTreeFolderHierarchy.NodeContextClick, AddressOf tvnodecontextclic

Catch ex As Exception

Dim RadTreeNodeRoot As New Telerik.Web.UI.RadTreeNode(_WorkEmail)

m_RadTreeFolderHierarchy.Nodes.Add(RadTreeNodeRoot)

RadTreeNodeRoot =

New Telerik.Web.UI.RadTreeNode(ex.Message)

m_RadTreeFolderHierarchy.Nodes.Add(RadTreeNodeRoot)

End Try

Try

' ADD Defaul Menu for tree

m_RadTreeFolderHierarchy.ContextMenus.Add(

New RadTreeViewContextMenu())

m_RadTreeFolderHierarchy.ContextMenus(0).LoadContentFile(

"~/TreeSupport/TreeMenu.xml")

' Menu for My Matters (Clients) top level.

m_RadTreeFolderHierarchy.ContextMenus.Add(

New RadTreeViewContextMenu())

m_RadTreeFolderHierarchy.ContextMenus(1).LoadContentFile(

"~/TreeSupport/ClientsMenu.xml")

' Menu for client record

m_RadTreeFolderHierarchy.ContextMenus.Add(

New RadTreeViewContextMenu())

m_RadTreeFolderHierarchy.ContextMenus(2).LoadContentFile(

"~/TreeSupport/ClientMenu.xml")

Catch ex As Exception

End Try

'add tree to panel

wrapPanel.Controls.Add(m_RadTreeFolderHierarchy)

'add a label control

_timeLabel =

New Label()

_timeLabel.Text = DateTime.Now.ToLongTimeString()

wrapPanel.Controls.Add(_timeLabel)

' add label to panel

Dim linebreak As Label = New Label()

linebreak.Text =

" "

wrapPanel.Controls.Add(linebreak)

' add label to panel

'add a label control

_statusLabel =

New Label()

_statusLabel.Text = msgTxt

wrapPanel.Controls.Add(_statusLabel)

' add label to panel

wrapPanel.Controls.Add(linebreak)

' add label to panel

' add user textbox

wrapPanel.Controls.Add(_txtUserid) ' add label to panel

Dim ajaxManager As RadAjaxManager = RadAjaxManager.GetCurrent(Me.Page)

If ajaxManager Is Nothing Then

ajaxManager =

New RadAjaxManager()

ajaxManager.ID =

"RadAjaxManager1"

Controls.Add(ajaxManager)

Me.Page.Items.Add(GetType(RadAjaxManager), ajaxManager)

End If

'20080911 bac using ajaxManager instead of

ajaxManager.AjaxSettings.AddAjaxSetting(m_RadTreeFolderHierarchy, wrapPanel)

' Me.Controls.Add(m_RadTreeFolderHierarchy)

End Sub

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 03 Oct 2008, 09:10 AM
Hi Bob,

I have examined the code you have sent us and suspect that the cause for this behavior is the way you are creating the controls. Can you please try using CreateChildControls instead creating them inside OnLoad? Also please note, that you should assign values for controls' IDs and they should not be changed across postbacks.

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Bob
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or