Hi All!
Instead of using the session to save/load the DockState for a page, I would like to use the Profiles. I've not been able to figure out how though. Has anyone got a working example - including the web.config profile definitions?
I'm more than a little desparate. hehe
Cheers
Mark.
Instead of using the session to save/load the DockState for a page, I would like to use the Profiles. I've not been able to figure out how though. Has anyone got a working example - including the web.config profile definitions?
I'm more than a little desparate. hehe
Cheers
Mark.
10 Answers, 1 is accepted
0
BSolveIT
Top achievements
Rank 2
answered on 02 Oct 2007, 03:33 PM
On second thoughts, forget the above.
I've been spending some time going through the PortalSiteVB project, and I really like the way it works. However, has anyone extended it such that it works on a per user basis?
I've been spending some time going through the PortalSiteVB project, and I really like the way it works. However, has anyone extended it such that it works on a per user basis?
0
Hello BSolveIT,
I believe this was discussed in another thread with you. I kindly suggest that we continue the discussion there. The community of course is welcome to share their experience on the matter.
Best wishes,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I believe this was discussed in another thread with you. I kindly suggest that we continue the discussion there. The community of course is welcome to share their experience on the matter.
Best wishes,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
BSolveIT
Top achievements
Rank 2
answered on 03 Oct 2007, 11:19 AM
Hi Petya
The other place this is being discussed is in a support ticket thread, not a public forum thread. You might want to copy the answer you gave me in the support ticket to here though?
Cheers
Mark
The other place this is being discussed is in a support ticket thread, not a public forum thread. You might want to copy the answer you gave me in the support ticket to here though?
Cheers
Mark
0
Hello BSolveIT,
Here is the code as requested by you, now attached in the forum thread. The application demonstrates our PortalSiteVB demo modified to have a Login page and store information about each user in the database so docks state is saved for each user and loaded when this exact user logs in. The application does not use Profiles, but it demonstrates a possible approach to saving state as per user basis.
Sincerely yours,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Here is the code as requested by you, now attached in the forum thread. The application demonstrates our PortalSiteVB demo modified to have a Login page and store information about each user in the database so docks state is saved for each user and loaded when this exact user logs in. The application does not use Profiles, but it demonstrates a possible approach to saving state as per user basis.
Sincerely yours,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
BSolveIT
Top achievements
Rank 2
answered on 04 Oct 2007, 12:40 PM
This is brilliant! Thanks!
However, it still leaves the problem of anonymous users? We want all users, including anonymous, to be able to see our pages and move things around, etc. We don't want to keep any data relating to the anonymous users after their session has expired though.
Any thoughts?
Cheers
Mark.
However, it still leaves the problem of anonymous users? We want all users, including anonymous, to be able to see our pages and move things around, etc. We don't want to keep any data relating to the anonymous users after their session has expired though.
Any thoughts?
Cheers
Mark.
0
Hi BSolveIT,
For the anonymous users here is one suggestion. We do not have an example to demonstrate it however.
1. Add a new user account for anonymous users in the database table Users
2. You could add a link in the Login page and in code-behind if this link was pressed store in Session["UserID"] the ID of an Anonymous account in the database that you have added.
3. Redirect the anonymous user to the main page where instead of loading information from the database with some preserved state for this special account, you delete all information in DB for the anonymous user and start with no information. In this way the anonymous user will always have an initial start with no previously saved data.
4. Throughout the work of the anonymous user, information will be updated in DB (if you want otherwise, then you will have to modify the current code a lot)
This is just a suggestion and it might have its drawbacks. Hope you still find it useful. The question is general as a whole and a bit aside from RadDock as a control but we still tried to offer an idea. In case some other questions concerning specifically our controls arise, feel free to ask.
Greetings,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
For the anonymous users here is one suggestion. We do not have an example to demonstrate it however.
1. Add a new user account for anonymous users in the database table Users
2. You could add a link in the Login page and in code-behind if this link was pressed store in Session["UserID"] the ID of an Anonymous account in the database that you have added.
3. Redirect the anonymous user to the main page where instead of loading information from the database with some preserved state for this special account, you delete all information in DB for the anonymous user and start with no information. In this way the anonymous user will always have an initial start with no previously saved data.
4. Throughout the work of the anonymous user, information will be updated in DB (if you want otherwise, then you will have to modify the current code a lot)
This is just a suggestion and it might have its drawbacks. Hope you still find it useful. The question is general as a whole and a bit aside from RadDock as a control but we still tried to offer an idea. In case some other questions concerning specifically our controls arise, feel free to ask.
Greetings,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
BSolveIT
Top achievements
Rank 2
answered on 05 Oct 2007, 04:36 PM
I've been working on a very similar type of solution.
I've decided to assume that all users are anonymous, at least to begin with (which of course they are - at least to begin with) and so in the web.config I have:
in the Global.asax:
I then use this as the Username to store in the users table, and get the ID of this new user, which is stored in the users profile.
I then had to update the function GetPageIdForCurrentUser in the PageInfo class, so that it adds a new entry in the pages table for new users:
So the database is then used as normal for this users session.
If the user then registers (using the proper memberhsips and roles system), I migrate the anonymous users profile.
(how to: MSDN: Migrate Anonymous Users)
Thats about it.
I've decided to assume that all users are anonymous, at least to begin with (which of course they are - at least to begin with) and so in the web.config I have:
| <anonymousIdentification enabled="true" cookieSlidingExpiration="true" /> |
in the Global.asax:
| Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) |
| If Not User.Identity.IsAuthenticated Then |
| Session("Anonymous") = Request.AnonymousID |
| Dim userID As Object = UserInfo.GetUserID(Session("Anonymous")) |
| If userID IsNot Nothing Then |
| Session("UserID") = Int32.Parse(userID.ToString()) |
| Else |
| Using connection As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Using command As New SqlCommand("INSERT INTO Users (username) VALUES(@Username);" _ |
| & "SELECT CAST(scope_identity() AS int);", connection) |
| command.Parameters.AddWithValue("@Username", Session("Anonymous")) |
| userID = command.ExecuteScalar() |
| Session("UserID") = Int32.Parse(userID.ToString()) |
| End Using |
| End Using |
| End If |
| Else |
| Dim userID As Object = UserInfo.GetUserID(User.Identity.Name) |
| If userID IsNot Nothing Then |
| Session("UserID") = Int32.Parse(userID.ToString()) |
| Else |
| End If |
| End If |
| End Sub |
I then use this as the Username to store in the users table, and get the ID of this new user, which is stored in the users profile.
I then had to update the function GetPageIdForCurrentUser in the PageInfo class, so that it adds a new entry in the pages table for new users:
| Public Shared Function GetPageIdForCurrentUser(ByVal userID As Integer, ByVal PageRef As Integer) As Integer |
| Using connection As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Using command As New SqlCommand("SELECT * FROM Pages WHERE UserID = @UserID AND PageRef = @PageRef", connection) |
| command.Parameters.AddWithValue("@UserID", userID) |
| command.Parameters.AddWithValue("@PageRef", PageRef) |
| Dim asdasd As Object = command.ExecuteScalar() |
| Dim PageID As Integer = CInt(asdasd) |
| If PageID = 0 Then |
| Using connection2 As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Using command2 As New SqlCommand("INSERT INTO Pages (PageRef, UserID) VALUES(@PageRef, @UserID);" _ |
| & "SELECT CAST(scope_identity() AS int);", connection) |
| command2.Parameters.AddWithValue("@UserID", userID) |
| command2.Parameters.AddWithValue("@PageRef", PageRef) |
| asdasd = command2.ExecuteScalar() |
| PageID = CInt(asdasd.ToString()) |
| End Using |
| End Using |
| End If |
| Return PageID |
| End Using |
| End Using |
| End Function |
So the database is then used as normal for this users session.
If the user then registers (using the proper memberhsips and roles system), I migrate the anonymous users profile.
(how to: MSDN: Migrate Anonymous Users)
Thats about it.
0
BSolveIT
Top achievements
Rank 2
answered on 06 Oct 2007, 03:45 PM
By the way, the pages table in the database in the LoginPortalSiteVB.zip project above doesn't match up with the PageInfo class.
In my solution (snippets above) I altered both the pages table and the PageInfo class, but only slightly.
My new PageInfo.vb class is as follows:
I thought I should post this in case anyone is trying to follow/implement the same.
- Mark
In my solution (snippets above) I altered both the pages table and the PageInfo class, but only slightly.
My new PageInfo.vb class is as follows:
| Imports System |
| Imports System.Data |
| Imports System.Configuration |
| Imports System.Web |
| Imports System.Web.Security |
| Imports System.Web.UI |
| Imports System.Web.UI.WebControls |
| Imports System.Web.UI.WebControls.WebParts |
| Imports System.Web.UI.HtmlControls |
| Imports System.Data.SqlClient |
| Imports System.Collections.Generic |
| Public Class PageInfo |
| Public Shared Function [Select](id As Integer) As PageInfo |
| Dim connection As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Try |
| Dim command As New SqlCommand("SELECT * FROM Pages WHERE PageID = @PageID", connection) |
| Try |
| command.Parameters.AddWithValue("@PageID", id) |
| Dim reader As SqlDataReader = command.ExecuteReader() |
| Try |
| If reader.Read() Then |
| Return New PageInfo(reader) |
| End If |
| Finally |
| reader.Dispose() |
| End Try |
| Finally |
| command.Dispose() |
| End Try |
| Finally |
| connection.Dispose() |
| End Try |
| Return Nothing |
| End Function 'Select |
| Public Shared Function GetPageIdForCurrentUser(ByVal userID As Integer, ByVal PageRef As Integer) As Integer |
| Using connection As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Using command As New SqlCommand("SELECT * FROM Pages WHERE UserID = @UserID AND PageRef = @PageRef", connection) |
| command.Parameters.AddWithValue("@UserID", userID) |
| command.Parameters.AddWithValue("@PageRef", PageRef) |
| Dim asdasd As Object = command.ExecuteScalar() |
| Dim PageID As Integer = CInt(asdasd) |
| If PageID = 0 Then |
| Using connection2 As SqlConnection = CommonDataAccess.GetOpenConnection() |
| Using command2 As New SqlCommand("INSERT INTO Pages (PageRef, UserID) VALUES(@PageRef, @UserID);" _ |
| & "SELECT CAST(scope_identity() AS int);", connection) |
| command2.Parameters.AddWithValue("@UserID", userID) |
| command2.Parameters.AddWithValue("@PageRef", PageRef) |
| asdasd = command2.ExecuteScalar() |
| PageID = CInt(asdasd.ToString()) |
| End Using |
| End Using |
| End If |
| Return PageID |
| End Using |
| End Using |
| End Function |
| Public Sub New(reader As SqlDataReader) |
| _PageID = CInt(reader("PageID")) |
| _PageRef = CInt(reader("PageRef")) |
| _UserID = CStr(reader("UserID")) |
| End Sub 'New |
| Public ReadOnly Property ID() As Integer |
| Get |
| Return _PageID |
| End Get |
| End Property |
| Public Property PageRef() As Integer |
| Get |
| Return _PageRef |
| End Get |
| Set(ByVal value As Integer) |
| _PageRef = value |
| End Set |
| End Property |
| Public Property UserID() As Integer |
| Get |
| Return _UserID |
| End Get |
| Set(ByVal value As Integer) |
| _UserID = value |
| End Set |
| End Property |
| Private _PageID As Integer |
| Private _PageRef As Integer |
| Private _UserID As Integer |
| End Class 'PageInfo |
I thought I should post this in case anyone is trying to follow/implement the same.
- Mark
0
Hi BSolveIT,
Thank you for the provided code and suggestions. Your active participation in our community has been greatly appreciated.
Regards,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for the provided code and suggestions. Your active participation in our community has been greatly appreciated.
Regards,
Petya
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Joff
Top achievements
Rank 1
answered on 05 Sep 2012, 02:33 AM
For those wishing to do this in C#
I wanted to create this as a custom control that I could drop into a web application, so instead of Default.aspx, I created PageWidgets.ascx - I also bypassed the login page, as I will be using authentication built into our CMS to authenticate users. In the example below, I have just used a set user ID of 2.
This could quite easily be customised back to using the Login process as the original example showed.
I hope the following is of assitance to someone, as the forums here have been very sueful to me.
Cheers
BaseWidget.cs
CommonDataAccess.cs
I wanted to create this as a custom control that I could drop into a web application, so instead of Default.aspx, I created PageWidgets.ascx - I also bypassed the login page, as I will be using authentication built into our CMS to authenticate users. In the example below, I have just used a set user ID of 2.
This could quite easily be customised back to using the Login process as the original example showed.
I hope the following is of assitance to someone, as the forums here have been very sueful to me.
Cheers
BaseWidget.cs
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace WebUI.CustomControlsIntranet{ public abstract class BaseWidget : System.Web.UI.UserControl { public string Configuration { get { return _configuration; } set { _configuration = value; Initialize(); } } protected abstract void Initialize(); private string _configuration; }}CommonDataAccess.cs
PageInfo.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;namespaceWebUI.CustomControlsIntranet{publicclassCommonDataAccess{publicstaticSqlConnection GetOpenConnection(){SqlConnection connection =newSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ToString());connection.Open();returnconnection;}}}PageWidgetInfo.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;usingSystem.Collections.Generic;namespaceWebUI.CustomControlsIntranet{publicclassPageInfo{publicstaticPageInfo Select(intid){SqlConnection connection = CommonDataAccess.GetOpenConnection();try{SqlCommand command =newSqlCommand("SELECT * FROM Pages WHERE PageID = @PageID", connection);try{command.Parameters.AddWithValue("@PageID", id);SqlDataReader reader = command.ExecuteReader();try{if(reader.Read()) {returnnewPageInfo(reader);}}finally{reader.Dispose();}}finally{command.Dispose();}}finally{connection.Dispose();}returnnull;}//SelectpublicstaticintGetPageIdForCurrentUser(intuserID){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()) {using(SqlCommand command =newSqlCommand("SELECT * FROM Pages WHERE UserID = @UserID", connection)) {command.Parameters.AddWithValue("@UserID", userID);objectasdasd = command.ExecuteScalar();returnConvert.ToInt32(asdasd);}}}publicPageInfo(SqlDataReader reader){_id = Convert.ToInt32(reader["PageID"]);_name = Convert.ToString(reader["Name"]);_path = Convert.ToString(reader["Path"]);}//NewpublicintID {get{return_id; }}publicstringPath {get{return_path; }set{ _path = value; }}publicstringName {get{return_name; }set{ _name = value; }}privateint_id;privatestring_name;privatestring_path;}}UserInfo.csusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;usingTelerik.Web.UI;namespaceWebUI.CustomControlsIntranet{publicclassPageWidgetInfo : IComparable<PageWidgetInfo>{publicstaticList<PageWidgetInfo> SelectAllWidgets(intuserId){List<PageWidgetInfo> widgets =newList<PageWidgetInfo>();using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT * FROM PageWidget INNER JOIN Widgets ON PageWidget.WidgetID = Widgets.WidgetID INNER JOIN Pages ON Pages.PageID = PageWidget.PageID WHERE Pages.UserID = @UserID", connection)){command.Parameters.AddWithValue("@UserID", userId);using(SqlDataReader reader = command.ExecuteReader()){while(reader.Read()){widgets.Add(newPageWidgetInfo(reader));}}}}returnwidgets;}publicstaticPageWidgetInfo Select(intpageWidgetID){List<PageWidgetInfo> widgets =newList<PageWidgetInfo>();using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT * FROM PageWidget INNER JOIN Widgets ON PageWidget.WidgetID = Widgets.WidgetID WHERE PageWidgetID = @PageWidgetID", connection)){command.Parameters.AddWithValue("@PageWidgetID", pageWidgetID);using(SqlDataReader reader = command.ExecuteReader()){if(reader.Read()){returnnewPageWidgetInfo(reader);}}}}returnnull;}publicstaticList<PageWidgetInfo> SelectPageWidgets(intpageID){List<PageWidgetInfo> widgets =newList<PageWidgetInfo>();using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT * FROM PageWidget INNER JOIN Widgets ON PageWidget.WidgetID = Widgets.WidgetID WHERE PageWidget.PageID = @PageID", connection)){command.Parameters.AddWithValue("@PageID", pageID);using(SqlDataReader reader = command.ExecuteReader()){while(reader.Read()){widgets.Add(newPageWidgetInfo(reader));}}}}returnwidgets;}publicstaticvoidDelete(intpageWidgetID){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("DELETE FROM PageWidget WHERE PageWidgetID = @PageWidgetID", connection)){command.Parameters.AddWithValue("@PageWidgetID", pageWidgetID);command.ExecuteNonQuery();}}}publicstaticvoidDeletePageWidgets(intpageID){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("DELETE FROM PageWidget WHERE PageID = @PageID", connection)){command.Parameters.AddWithValue("@PageID", pageID);command.ExecuteNonQuery();}}}publicstaticPageWidgetInfo Insert(intpageID,intwidgetID,stringconfiguration,stringstate){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("INSERT INTO PageWidget (PageID, WidgetID, Configuration, State) VALUES (@PageID, @WidgetID, @Configuration, @State) SELECT @@IDENTITY", connection)){command.Parameters.AddWithValue("@PageID", pageID);command.Parameters.AddWithValue("@WidgetID", widgetID);command.Parameters.AddWithValue("@Configuration", configuration);command.Parameters.AddWithValue("@State", state);objectnewID = command.ExecuteScalar();returnSelect(Convert.ToInt32(Convert.ToDecimal(newID)));}}}publicvoidUpdate(){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("UPDATE PageWidget SET Configuration=@Configuration, State=@State WHERE PageWidgetID = @PageWidgetID", connection)){command.Parameters.AddWithValue("@State", State);command.Parameters.AddWithValue("@Configuration", Configuration);command.Parameters.AddWithValue("@PageWidgetID", ID);command.ExecuteNonQuery();}}}publicPageWidgetInfo(SqlDataReader reader){_id = (int)reader["PageWidgetID"];_pageID = (int)reader["PageID"];_widgetID = (int)reader["WidgetID"];_name = (string)reader["Name"];_path = (string)reader["Path"];_configuration = (string)reader["Configuration"];_state = (string)reader["State"];}publicintID{get{return_id; }}publicintPageID{get{return_pageID; }}publicintWidgetID{get{return_widgetID; }}publicstringName{get{return_name; }}publicstringPath{get{return_path; }}publicstringConfiguration{get{return_configuration; }set{ _configuration = value; }}publicstringState{get{return_state; }set{ _state = value; }}publicDockState DockState{get{if(_dockState ==null){_dockState = Telerik.Web.UI.DockState.Deserialize(_state);}return_dockState;}}privatestring_configuration;privateint_id;privateint_pageID;privateint_widgetID;privatestring_name;privatestring_path;privatestring_state;privateDockState _dockState;publicintCompareTo(PageWidgetInfo obj){returnDockState.Index.CompareTo(obj.DockState.Index);}}}WidgetInfo.csusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Data.SqlClient;namespaceWebUI.CustomControlsIntranet{publicclassUserInfo{publicstaticobjectGetUserID(stringusername,stringpassword){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT [userID] FROM Users WHERE [username]=@Username AND [password]=@Password", connection)){command.Parameters.AddWithValue("@Username", username);command.Parameters.AddWithValue("@Password", password);returncommand.ExecuteScalar();}}}}}usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;namespaceWebUI.CustomControlsIntranet{publicclassWidgetInfo{publicstaticWidgetInfo Select(intwidgetID){using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT * FROM Widgets WHERE WidgetID = @WidgetID", connection)){command.Parameters.AddWithValue("@WidgetID", widgetID);using(SqlDataReader reader = command.ExecuteReader()){if(reader.Read()){returnnewWidgetInfo(reader);}}}}returnnull;}publicstaticList<WidgetInfo> Select(){List<WidgetInfo> widgets =newList<WidgetInfo>();using(SqlConnection connection = CommonDataAccess.GetOpenConnection()){using(SqlCommand command =newSqlCommand("SELECT * FROM Widgets", connection)){using(SqlDataReader reader = command.ExecuteReader()){while(reader.Read()){widgets.Add(newWidgetInfo(reader));}}}}returnwidgets;}publicWidgetInfo(SqlDataReader reader){_id = (int)reader["WidgetID"];_name = (string)reader["Name"];_path = (string)reader["Path"];}publicintID{get{return_id; }}publicstringPath{get{return_path; }}publicstringName{get{return_name; }}privateint_id;privatestring_name;privatestring_path;}}With the code behind<%@ Control Language="C#"AutoEventWireup="true"CodeBehind="PageWidgets.ascx.cs"Inherits="WebUI.CustomControlsIntranet.PageWidgetClass"%><%@ Register Assembly="Telerik.Web.UI"Namespace="Telerik.Web.UI"TagPrefix="telerik"%><div><asp:scriptmanager runat="server"id="ScriptManager1"></asp:scriptmanager>Widget Configuration:<asp:textbox runat="server"id="TextConfiguration"></asp:textbox><asp:dropdownlist runat="server"id="ListWidgets"></asp:dropdownlist><asp:button runat="server"id="ButtonAddDock"text="Add Dock"onclick="ButtonAddDock_Click"/><telerik:raddocklayout id="DockLayout"runat="server"onloaddocklayout="DockLayout_LoadDockLayout"onsavedocklayout="DockLayout_SaveDockLayout"storelayoutinviewstate="false"><div><telerik:raddockzone runat="server"id="ZoneLeft"style="float: left; margin-right: 10px;"width="45%"minheight="200px"></telerik:raddockzone><telerik:raddockzone runat="server"id="ZoneRight"style="float: left;"minheight="200px"width="45%"></telerik:raddockzone></div><div style="display: none"><asp:updatepanel runat="server"id="UpdatePanel1"><triggers><asp:asyncpostbacktrigger controlid="ButtonAddDock"eventname="Click"/></triggers></asp:updatepanel></div></telerik:raddocklayout><asp:loginstatus id="LoginStatus1"runat="server"logoutpageurl="~/Login.aspx"/><asp:hiddenfield id="currentPageId"runat="server"/></div>usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Collections.Generic;usingTelerik.Web.UI;namespaceWebUI.CustomControlsIntranet{publicpartialclassPageWidgetClass : System.Web.UI.UserControl{//Private PageID As Integer = 1privateList<PageWidgetInfo> _pageWidgets;protectedList<PageWidgetInfo> PageWidgets {get{if(_pageWidgets ==null) {// int userId = Int32.Parse(Session["UserId"].ToString());intuserId = 2;currentPageId.Value = PageInfo.GetPageIdForCurrentUser(userId).ToString();_pageWidgets = PageWidgetInfo.SelectAllWidgets(userId);}return_pageWidgets;}}protectedoverridevoidOnInit(EventArgs e){foreach(PageWidgetInfo pageWidgetinPageWidgets) {RadDock dock = CreateDock(pageWidget);DockLayout.Controls.Add(dock);CreateSaveStateTriggers(dock);}base.OnInit(e);}protectedoverridevoidOnLoad(EventArgs e){if(!IsPostBack) {ListWidgets.DataSource = WidgetInfo.Select();ListWidgets.DataTextField ="Name";ListWidgets.DataValueField ="ID";ListWidgets.DataBind();}base.OnLoad(e);}protectedRadDock CreateDock(PageWidgetInfo pageWidgetInfo){RadDock dock =newRadDock();dock.ApplyState(pageWidgetInfo.DockState);dock.ID = pageWidgetInfo.ID.ToString();dock.Tag = pageWidgetInfo.ID.ToString();BaseWidget widget = LoadControl(pageWidgetInfo.Path)asBaseWidget;if(widget ==null) {thrownewException(string.Format("The UserControl with path '{0}' does not inherit from BaseWidget. All widgets must inherit from BaseWidget.", pageWidgetInfo.Path));}dock.ContentContainer.Controls.Add(widget);widget.Configuration = pageWidgetInfo.Configuration;//Currently, there is a problem with the RadDock command items:// if they are not explicitly created, the Command event it not fired.dock.Commands.Add(newDockCloseCommand());dock.Commands.Add(newDockExpandCollapseCommand());dock.Command += Dock_Command;returndock;}protectedRadDock CreateDock(intwidgetID,stringwidgetConfiguration){WidgetInfo widget = WidgetInfo.Select(widgetID);if(widget ==null) {thrownewException(string.Format("Cannot find a Widget with ID={0}.", widgetID));}PageWidgetInfo newPageWidget = PageWidgetInfo.Insert(Int32.Parse(currentPageId.Value), widgetID, widgetConfiguration,string.Empty);PageWidgets.Add(newPageWidget);RadDock dock = CreateDock(newPageWidget);dock.Title = widget.Name;returndock;}protectedvoidDock_Command(objectsender, DockCommandEventArgs e){if(e.Command.Name =="Close") {ScriptManager.RegisterStartupScript(UpdatePanel1,this.GetType(),"RemoveDock",string.Format("function _removeDock() {{"+"Sys.Application.remove_load(_removeDock);"+"$find('{0}').undock();"+"$get('{1}').appendChild($get('{0}'));"+"$find('{0}').doPostBack('DockPositionChanged');"+"}};"+"Sys.Application.add_load(_removeDock);", ((RadDock)sender).ClientID, UpdatePanel1.ClientID),true);}}privatePageWidgetInfo FindWidget(intid){foreach(PageWidgetInfo infoinPageWidgets) {if(info.ID == id) {returninfo;}}returnnull;}protectedvoidDockLayout_SaveDockLayout(objectsender, DockLayoutEventArgs e){foreach(DockState stateinDockLayout.GetRegisteredDocksState()) {intstateWidgetID =int.Parse(state.Tag);PageWidgetInfo pageWidget = FindWidget(stateWidgetID);if((pageWidget !=null) && !state.Closed) {pageWidget.State = state.ToString();pageWidget.Update();}else{PageWidgetInfo.Delete(stateWidgetID);}}}privatevoidCreateSaveStateTriggers(RadDock dock){dock.AutoPostBack =true;dock.CommandsAutoPostBack =true;AsyncPostBackTrigger saveStateTrigger =newAsyncPostBackTrigger();saveStateTrigger.ControlID = dock.ID;saveStateTrigger.EventName ="DockPositionChanged";UpdatePanel1.Triggers.Add(saveStateTrigger);saveStateTrigger =newAsyncPostBackTrigger();saveStateTrigger.ControlID = dock.ID;saveStateTrigger.EventName ="Command";UpdatePanel1.Triggers.Add(saveStateTrigger);}protectedvoidButtonAddDock_Click(objectsender, EventArgs e){RadDock dock = CreateDock(int.Parse(ListWidgets.SelectedValue), TextConfiguration.Text);UpdatePanel1.ContentTemplateContainer.Controls.Add(dock);CreateSaveStateTriggers(dock);ScriptManager.RegisterStartupScript(dock,this.GetType(),"AddDock",string.Format("function _addDock() {{"+"Sys.Application.remove_load(_addDock);"+"$find('{1}').dock($find('{0}'));"+"$find('{0}').doPostBack('DockPositionChanged');"+"}};"+"Sys.Application.add_load(_addDock);", dock.ClientID, ZoneLeft.ClientID),true);}protectedvoidDockLayout_LoadDockLayout(objectsender, DockLayoutEventArgs e){foreach(PageWidgetInfo pageWidgetinPageWidgets){e.Positions[pageWidget.DockState.UniqueName] = pageWidget.DockState.DockZoneID;e.Indices[pageWidget.DockState.UniqueName] = pageWidget.DockState.Index;}}}}