开发者

Telerik Dock is duplicating boxes and "_breaking_" the webpage, how can I fix the problem?

Here is the Code: VB: Imports System.Web.Script.Serialization

Pa开发者_如何学JAVArtial Class MyLanding Inherits System.Web.UI.Page Private LoginClass As New LoginClass Private _dockStateCleared As Boolean = False Private _conn As New SqlConnection(ConfigurationManager.ConnectionStrings("MidwestPartsConnectionString").ConnectionString)

Private ReadOnly Property CurrentDockStates() As List(Of DockState)
    Get
        'Get saved state string from the database - set it to dockState variable for example 
        Dim dockStatesFromDB As String = ""

        _conn.Open()
        Dim command As New SqlCommand("SELECT JavascriptStr FROM SysProperties WHERE (UserID = @UserID)", _conn)
        command.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = Me.LoginClass.ReturnUserID()
        Try
            dockStatesFromDB = command.ExecuteScalar().ToString()
            _conn.Close()
        Catch ex As Exception
            _conn.Close()
            Me.CreateSavedLayout("")
        End Try

        Dim _currentDockStates As New List(Of DockState)()
        Dim stringStates As String() = dockStatesFromDB.Split("|"c)
        For Each stringState As String In stringStates
            If stringState.Trim() <> String.Empty Then
                _currentDockStates.Add(DockState.Deserialize(stringState))
            End If
        Next
        Return _currentDockStates
    End Get
End Property


Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    If Not Page.IsPostBack Then
        If CurrentDockStates.Count = 0 Then
            Me.LoadItems()
        End If
    End If
End Sub

Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
    Dim i As Integer = 0
    While i < CurrentDockStates.Count
        If CurrentDockStates(i).Closed = False Then
            Dim dock As RadDock = CreateRadDockFromState(CurrentDockStates(i))
            dlColumnOne.Controls.Add(dock)
            CreateSaveStateTrigger(dock)
            LoadUserControl(dock)
        End If
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
End Sub

Protected Sub dlColumnOne_LoadDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs)
    For Each state As DockState In CurrentDockStates
        e.Positions(state.UniqueName) = state.DockZoneID
        e.Indices(state.UniqueName) = state.Index
    Next
End Sub
Protected Sub dlColumnOne_SaveDockLayout(ByVal sender As Object, ByVal e As DockLayoutEventArgs)
    Dim stateList As List(Of DockState) = dlColumnOne.GetRegisteredDocksState()
    Dim serializedList As New StringBuilder()
    Dim i As Integer = 0

    While i < stateList.Count
        serializedList.Append(stateList(i).ToString())
        serializedList.Append("|")
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While

    Dim dockState As String = serializedList.ToString()
    If dockState.Trim() <> [String].Empty Then
        _conn.Open()
        Dim command As New SqlCommand([String].Format("update sysproperties set javascriptstr = '{0}' Where UserID = @UserID ", dockState), _conn)
        command.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = Me.LoginClass.ReturnUserID()
        command.ExecuteNonQuery()
        _conn.Close()
    End If
End Sub

Private Function CreateRadDockFromState(ByVal state As DockState) As RadDock
    Dim dock As New RadDock()
    dock.DockMode = DockMode.Docked
    dock.UniqueName = state.UniqueName
    dock.ID = String.Format("RadDock{0}", dock.UniqueName)
    dock.ApplyState(state)
    dock.Commands.Add(New DockCloseCommand())
    dock.Commands.Add(New DockExpandCollapseCommand())
    Return dock
End Function

Private Function CreateRadDock(ByVal DockTitle As String) As RadDock
    Dim docksCount As Integer = CurrentDockStates.Count
    Dim dock As New RadDock
    dock.DockMode = DockMode.Docked
    Dim UniqueName As String = Guid.NewGuid().ToString()
    UniqueName = UniqueName.Replace("-", "")
    dock.UniqueName = UniqueName
    dock.ID = String.Format("RadDock{0}", UniqueName)
    dock.Title = DockTitle
    dock.Width = Unit.Pixel(400)
    dock.Commands.Add(New DockCloseCommand())
    dock.Commands.Add(New DockExpandCollapseCommand())
    Return dock
End Function

Private Sub LoadItems()
    Dim DocksDataTable As DataTable = Me.ReturnReports()
    For i = 0 To DocksDataTable.Rows.Count() - 1
        Dim dock As RadDock = Me.CreateRadDock(DocksDataTable.Rows(i).Item("ReportTitle").ToString())
        Dim dz As RadDockZone = Me.dzColumnOne
        Dim dl As RadDockLayout = Me.dlColumnOne
        dz.Controls.Add(dock)
        Me.CreateSaveStateTrigger(dock)
        dock.Tag = DocksDataTable.Rows(i).Item("ReportPath")
        Me.LoadUserControl(dock)
    Next
End Sub

Public Function ReturnReports() As DataTable
    Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("MidwestPartsConnectionString").ConnectionString)
    Dim Query As String = "SELECT Reports.ReportPath, Reports.ReportTitle, UserReports.UserID FROM UserReports INNER JOIN Reports ON UserReports.ReportID = Reports.ReportID WHERE (UserReports.UserID = @UserID)"
    Dim adapter As New SqlDataAdapter
    adapter.SelectCommand = New SqlCommand(Query, connection)
    adapter.SelectCommand.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = Me.LoginClass.ReturnUserID()
    Dim table1 As New DataTable
    connection.Open()
    Try
        adapter.Fill(table1)
    Finally
        connection.Close()
    End Try
    Return table1
End Function

Private Function ReturnLayout() As DataTable
    Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("MidwestPartsConnectionString").ConnectionString)
    Dim Query As String = "select * from sysproperties"
    Dim adapter As New SqlDataAdapter
    adapter.SelectCommand = New SqlCommand(Query, connection)
    adapter.SelectCommand.Parameters.Add("@UserPropertiesID", SqlDbType.Int).Value = 1
    Dim table1 As New DataTable
    connection.Open()
    Try
        adapter.Fill(table1)
    Finally
        connection.Close()
    End Try
    Return table1
End Function

Private Sub LoadUserControl(ByVal dock As RadDock)
    If String.IsNullOrEmpty(dock.Tag) Then
        Return
    End If
    Dim usercontrol As Control = LoadControl(dock.Tag)
    dock.ContentContainer.Controls.Add(usercontrol)
End Sub

Private Sub CreateSaveStateTrigger(ByVal dock As RadDock)
    dock.AutoPostBack = True
    dock.CommandsAutoPostBack = True
    Dim saveStateTrigger As New AsyncPostBackTrigger()
    saveStateTrigger.ControlID = dock.ID
    saveStateTrigger.EventName = "DockPositionChanged"
    UpdatePanel1.Triggers.Add(saveStateTrigger)
    saveStateTrigger = New AsyncPostBackTrigger()
    saveStateTrigger.ControlID = dock.ID
    saveStateTrigger.EventName = "Command"
    UpdatePanel1.Triggers.Add(saveStateTrigger)
End Sub

Private Sub CreateSavedLayout(ByVal JavascriptStr As String)
    Dim sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("MidwestPartsConnectionString").ConnectionString)        
    Dim strSqlInsert As String = "INSERT INTO SysProperties(UserID, JavascriptStr) VALUES (@UserID, @JavascriptStr)"
    strSqlInsert += "; SELECT SCOPE_IDENTITY() ;"
    Dim sqlCmd As New SqlCommand(strSqlInsert, sqlConn)
    With sqlCmd.Parameters
        .Add("@JavascriptStr", SqlDbType.Text).Value = JavascriptStr
        .Add("@UserID", SqlDbType.UniqueIdentifier).Value = Me.LoginClass.ReturnUserID()
    End With
    sqlCmd.Connection.Open()
    sqlCmd.ExecuteScalar()
    sqlCmd.Connection.Close()
End Sub


Protected Sub btnAddReports_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddReports.Click
    Try
        Response.Redirect("~/MyUserAccount/SelectedReports.aspx", False)
    Catch ex As Exception

    End Try
End Sub

End Class


Your could looks fine. Possible reasons for this problem include the following:

  • Dragging the Dock control very quickly causes an ajax conflict, and an error is shown. To avoid this from happening you could show an AjaxLoading panel during the process of an ajax request (search/ask in the telerik forums for a sample showing how to do this). Additionally you should make sure the UpdatePanels on your site are configured as in the following online demo: http://demos.telerik.com/aspnet-ajax/dock/examples/myportal/defaultcs.aspx.

  • The error is a result of a ViewState problem. This telerik forum thread provides a possible solution: www.telerik.com/community/forums/aspnet-ajax/docking/failed-to-load-view-state-error-when-moving-dynamically-created-widgets-around-the-raddocklayout.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜