Free Download:
|
| |
| hareshgpatel | Asp.Net User |
| Completely Dynamic Webparts with drag-drop & ATLAS functionality | 9/17/2006 6:53:07 PM |
0/0 | |
|
Hi, I am trying to create ATLAS enabled Drag-Drop webparts dynamically (!) ..Webparts will be created from database. And so I've implemented custom WebpartManager, WebPart, WebPartZone, etc and I am instantiate them in OnInit() of the page. Now I have couple of problems... 1) On postback, webparts are gettind duplicated. I am pretty sure there is something to do with personalisation stored in ASPNETDB database (App_Data folder). I want to completely DISABLE the aspnetdb, because I am also authenticating users dynamically. 2) When I edit any webpart I get this exception... System.InvalidOperationException: Should only have editor parts in the ZoneTemplate of 'editor'. This is how I create EditZone: EditorZone editor = new EditorZone(); editor.ID = "editor"; PropertyGridEditorPart PropertyGridEditorPart1 = new PropertyGridEditorPart(); PropertyGridEditorPart1.Title = "Web Part properties"; editor.ZoneTemplate = new ControlHolder(PropertyGridEditorPart1);
here is the code for ControlHolder class public class ControlHolder : ITemplate { Control ctrl = new Control(); public ControlHolder() { ctrl.Controls.Clear(); ctrl.Controls.Add(new LiteralControl("control list is empty.")); } public ControlHolder(Control _ctrl) { ctrl.Controls.Clear(); if (_ctrl == null) { ctrl.Controls.Add(new LiteralControl("control list is empty.")); } else { ctrl.Controls.Add(_ctrl); } } void ITemplate.InstantiateIn(Control owner) { owner.Controls.Add(ctrl); } } Please help me solving above problems. Thanks, Haresh |
| BCdotNET | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 9/19/2006 9:31:39 AM |
0/0 | |
|
hareshgpatel: Hi, I am trying to create ATLAS enabled Drag-Drop webparts dynamically (!) ..Webparts will be created from database. And so I've implemented custom WebpartManager, WebPart, WebPartZone, etc and I am instantiate them in OnInit() of the page. Now I have couple of problems...
My collegues and I have been struggling with this also. Finally we've found a solution: everything can be standard (although our webparts are .ascx files which derive from a base class that inherits from IWebPart), however you need to use a custom CatalogPart in the CatalogZone's ZoneTemplate. Helpful sites: http://www.carlosag.net/articles/WebParts/catalogPartSample.aspx http://www.codeproject.com/aspnet/DropDownCatalogZone.asp Some sample code (but please make sure to look at http://www.carlosag.net/articles/WebParts/catalogPartSample.aspx , lots of it is derived from that example!): public class MyCatalogPart : CatalogPart
{
WebPartDescriptionCollection _description;
Dictionary<string, WebPart> _loadedWebparts;
public MyCatalogPart()
{
}
public override string Title
{
get
{
string title = base.Title;
return string.IsNullOrEmpty(title) ? "My Catalog Part" : title;
}
set
{
base.Title = value;
}
}
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions()
{
if (this.DesignMode)
{
return new WebPartDescriptionCollection(new object[] {
new WebPartDescription("1", "Xml WebPart 1", null, null),
new WebPartDescription("2", "Xml WebPart 2", null, null),
new WebPartDescription("3", "Xml WebPart 3", null, null)});
}
if (_description == null)
this.GetWebParts();
return this._description;
}
// VERY IMPORTANT -- NOT MENTIONED IN ARTICLES!
// to REMOVE the webparts from the catalog after adding them, you need code like this:
// if you don't do this, the webparts will still be present in the catalog after adding them
protected override void OnPreRender(EventArgs e)
{
string sCheckBoxKey = Zone.UniqueID + "$_checkbox";
string sActionKey = "__EVENTARGUMENT";
string sCheckBox = string.Empty;
if (HttpContext.Current.Request[sCheckBoxKey] != null)
{
sCheckBox = HttpContext.Current.Request[sCheckBoxKey].ToString();
}
string sAction = string.Empty;
if (HttpContext.Current.Request[sActionKey] != null)
{
sAction = HttpContext.Current.Request[sActionKey].ToString();
}
Hashtable htSelected = new Hashtable();
foreach (string sSel in sCheckBox.Split(','))
{
htSelected.Add(sSel, true);
}
if (sAction == "add" && _description != null)
{
List list = new List();
foreach (WebPartDescription oWPD in _description)
{
if (htSelected[oWPD.ID] == null)
{
list.Add(oWPD);
}
}
this._description = new WebPartDescriptionCollection(list);
}
base.OnPreRender(e);
}
private void GetWebParts()
{
WebPartDescription description = null;
List list = new List();
this._loadedWebparts = new Dictionary<string, WebPart>();
// retrieve the web parts from the database:
List lMWP = GetMyWebParts();
foreach (MyWebPart oMWP in lMWP)
{
WebPart oWP = CreateWebPartFromMyWebPart(oMWP);
if ((oWP != null) && ((base.WebPartManager == null) || (base.WebPartManager.IsAuthorized(oWP)) && (!IsWebPartLoaded(oWP))))
{
description = new WebPartDescription(oWP);
list.Add(description);
this._loadedWebparts.Add(description.ID, oWP);
}
}
this._description = new WebPartDescriptionCollection(list);
}
private WebPart CreateWebPartFromMyWebPart(MyWebPart oSWP)
{
WebPart webPart = null;
if (oSWP.Type.LastIndexOf(".ascx") > 0)
{
Control control = this.Page.LoadControl(oSWP.Type);
control.ID = oSWP.ID;
if (base.WebPartManager != null)
webPart = base.WebPartManager.CreateWebPart(control);
}
else
{
Type type = Type.GetType(oSWP.Type);
webPart = Activator.CreateInstance(type, null) as WebPart;
}
webPart.ID = oSWP.ID;
webPart.Title = oSWP.Title;
webPart.CatalogIconImageUrl = oSWP.ImageUrl;
webPart.AuthorizationFilter = oSWP.AuthorizationFilter;
return webPart;
}
private bool IsWebPartLoaded(WebPart oWP)
{
foreach (WebPart oWebPart in base.WebPartManager.WebParts)
{
if (oWP.Title == oWebPart.Title)
return true;
}
return false;
}
}
Life would be a lot easier if we could take a look at the source code. |
| VBMan | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/5/2006 2:58:16 PM |
0/0 | |
|
Hello, Can someone explain what this line is doing. Dictionary<string, WebPart> _loadedWebparts;
I've looked at the sample Catalog from Carlos and like the extras this sample suggest such as deleting from a Catalog. However, I work in VB and have an error when convert the entire Class to VB. Regardless of what I try I get an error that it doesn't know what Dictionary is. I tried this and other derivations. Private _loadedWebparts As Dictionary(Of String, WebPart) Thanks! |
| BCdotNET | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/9/2006 8:03:34 AM |
0/0 | |
|
VBMan: Can someone explain what this line is doing.
Dictionary<string, WebPart> _loadedWebparts; This contains the list of WebParts. Mind you, it could be not all of the code above is necessary, it's a cropped version of the code we use and some of it has to do with stuff we need. The best way to look at the code above is as inspiration, you don't need to slavishly follow it to succeed. Look at what it does, how it does it and why it does it (and when it does it).
Life would be a lot easier if we could take a look at the source code. |
| BCdotNET | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/11/2006 11:39:38 AM |
0/0 | |
|
Now I remember where _loadedWebparts is used: look at http://www.carlosag.net/articles/WebParts/catalogPartSample.aspx , there's public override WebPart GetWebPart(WebPartDescription description) and in our version of that method we do this: public override WebPart GetWebPart(WebPartDescription description)
{
if (this._loadedWebparts == null)
this.GetWebParts();
return this._loadedWebparts[description.ID];
} I don't know about using Dictionary in VB (and IMHO that question isn't relevant in this forum anyway). Perhaps you can use a HashTable instead?
Life would be a lot easier if we could take a look at the source code. |
| VBMan | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/12/2006 2:23:10 AM |
0/0 | |
|
BCdotNet, Thanks for trying to help. I am new to .net 2.0 and a VB programmer so learning C# on the fly is problematic at best. I am unable to resolve using your sample because the code I mentioned is not recognized in C#, so I expect either you have some background code to allow them to be used. These lines are not recognized without some type of additional coding/assemblies and without seeing a working sample I am unable to take the next step. Dictionary<string, WebPart> _loadedWebparts; List list = new List(); List list = new List(); this._loadedWebparts = new Dictionary<string, WebPart>(); These lines generate errors when trying to compile as List and Dictionary<...> are not recognized.
|
| BCdotNET | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/12/2006 7:39:14 AM |
0/0 | |
|
You need to "import" or "use" the proper classes. If you don't know which class List or Dictionary belongs to, use Visual Studio's help.
Life would be a lot easier if we could take a look at the source code. |
| ravi.kalyan | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/26/2006 5:47:18 AM |
0/0 | |
|
Hey, I am also having the same issue. We have a requirement of showing the webparts based on the database values.. ie., we will be creating the Dynamic Webpart and also the WebPartZone. When I try to populate the Webpart on to the UI, first time it shows fine but when I do the postback, the WebParts are getting duplicated. How can I resolve this error? Warm Regards, Ravi Kalyan |
| ravi.kalyan | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 10/27/2006 5:38:36 AM |
0/0 | |
|
BCdotNET: Look at the code above, and use it as a guide. We don't use dynamic WebPartZones, however, but we did solve the duplication problem.
Ya, I tried creating the CustomCatalogPart class extending from CatalogPart. But problem is that how can I add my custom class to CatalogZone? Please provide me any samples if u have. Regards
|
| sameerg | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 11/27/2006 6:54:23 AM |
0/0 | |
|
hi
i am following the link you have given here
http://www.carlosag.net/articles/WebParts/catalogPartSample.aspx
when i am running that application i am gettign error in the following funtion
public override WebPart GetWebPart(WebPartDescription description)
{
string typeName = this.GetTypeNameFromXml(description.ID);
Type type =Type.GetType(typeName);
return Activator.CreateInstance(type, null) as WebPart;
}
in the type i m not gettign the type of webpart type.. it returning null...
|
| sudhirkatiyar | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 12/14/2006 2:26:39 PM |
0/0 | |
|
Haresh,
I am also having the same situation where i wanted to use the authentication and not the personalisation stored in ASPNETDB database (App_Data folder). I want to completely DISABLE the aspnetdb, because I am also authenticating users dynamically.
Did you have any luck with your question and have you found any solution
Can share your example to this piece of code as how you were able to implement this
|
| hareshgpatel | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 12/25/2006 10:17:14 PM |
0/0 | |
|
Sudhir, This is how I DISABLED and DELETED the aspnetDB database from APP_Data folder:
1) In Web.Config file add the following ... <system.web> <webParts> <personalization defaultProvider="VoidPersonalizationProvider"> <providers> <add name="VoidPersonalizationProvider" type="MyApp.VoidPersonalizationProvider" /> </providers>
... </webParts> ...
2) Add VoidPersonalizationProvider class to your project using System; using System.IO; using System.Data; using System.Configuration; using System.Collections.Specialized; 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; using System.Web.Hosting; using System.Diagnostics;
namespace MyApp { //This class is just to disable ASPNETDB database public class VoidPersonalizationProvider : PersonalizationProvider { private string _applicationName;
public override string ApplicationName { get { if (string.IsNullOrEmpty(_applicationName)) _applicationName = HostingEnvironment.ApplicationVirtualPath; return _applicationName; } set { _applicationName = value; } }
public override void Initialize(string name, NameValueCollection configSettings) { base.Initialize(name, configSettings); }
public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords) { totalRecords = 1; return null; }
public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query) { return -1; }
public override int ResetUserState(string path, DateTime userInactiveSinceDate) { return 0; }
protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { }
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName) { }
public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames) { return 0; }
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { } }
}
3. Delete ASPNETDB database from APP_Data folder
|
| hareshgpatel | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 12/25/2006 11:17:32 PM |
0/0 | |
|
When you are adding weparts dynamically to a page, sometimes you might want to display/edit HTML "as is" from database into a webpart. For example, in CMS sort of applications. The following snippet can help you implement it. It also demonstrates a way to add EditorZone in a webpart for In-Place editing, like PageFlakes.
1) Create custom WebPart and add Html property to it public class MyWebPart : WebPart {
...
private string _strHtml = "[HTML Content not specified]";
...
[Personalizable(true)] [WebDisplayName("HTML Content")] [WebDescription("Use this property to set the HTML")] public string Html { get { return _strHtml; } set { _strHtml = value; } }
...
protected override void Render(HtmlTextWriter writer) {
writer.Write(Html); }
...
}
2) Create custom EditorZone to edit the Webpart
using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;
namespace MyApp {
public class MyEditorZone : EditorZone {
public MyEditorZone() {
this.HeaderText = " "; this.InstructionText = " "; }
// Override Render to add the editorzone in the current webpart being edited protected override void Render(HtmlTextWriter writer) {
MyWebPart webpart = (MyWebPart)this.WebPartToEdit;
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.StringWriter strWriter = new System.IO.StringWriter(strBuilder);
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
base.Render(htmlWriter);
// Displays EditorZone on top of webparts HTML content webpart.Html = strBuilder.ToString() + webpart.Html; } } }
3) Use MyEditorZone like a normal editorzone and you should see the EditorZone added to Webpart content.
... <form ...> ... <myTag:MyEditorZone ID="objEditorZone" runat="server"> <ZoneTemplate> <asp:PropertyGridEditorPart ID="PropertyGridEditorPart" runat="server" Title="Web Part properties" /> <%-- Add any other EditorParts you want --%> </ZoneTemplate> </myTag:MyEditorZone> ... </form> |
| ErMasca | Asp.Net User |
| Re: Completely Dynamic Webparts with drag-drop & ATLAS functionality | 2/2/2008 6:24:28 PM |
0/0 | |
|
i love it, i was thinkin on something like this.
i do create my editors from scracth, i do not use the webbrowsable at all,
namespace corecms.WebParts.Quote
{
public class QuotePart : WebPart
{
#region webpart properties
private string _title = "QuotePart";
private string _titleUrl = "";
private string _description = "Description : Quote Part. This web part allows user to add a quote.";
private string _subTitle = "";
private string _catalogIconImageUrl = "/images/SecondSimplePart.gif";
private string _titleIconImageUrl = "/images/SecondSimplePart.gif";
public override string Title
{
get { return _title; }
set { _title = value; }
}
public override string TitleUrl
{
get { return _titleUrl; }
set { _titleUrl = value; }
}
public override string Description
{
get { return _description; }
set { _description = value; }
}
public override string Subtitle
{
get { return _subTitle; }
}
public override string CatalogIconImageUrl
{
get { return _catalogIconImageUrl; }
set { _catalogIconImageUrl = value; }
}
public override string TitleIconImageUrl
{
get { return _titleIconImageUrl; }
set { _titleIconImageUrl = value; }
}
#endregion
#region Personalizable Properties
string _quote;
[Personalizable(PersonalizationScope.Shared)]
[DefaultValue("")]
public string quote
{
get { return _quote; }
set { _quote = value; }
}
string _quoteauthor;
[Personalizable(PersonalizationScope.Shared)]
[DefaultValue("Epicurious")]
public string quoteauthor
{
get { return _quoteauthor; }
set { _quoteauthor = value; }
}
int _imagefileid;
[Personalizable(PersonalizationScope.Shared)]
[DefaultValue("")]
public int imagefileid
{
get { return _imagefileid; }
set { _imagefileid = value; }
}
#endregion
QuoteEditor editorPart;
public QuotePart()
{
//
// TODO: Add constructor logic here
//
this.ChromeType = PartChromeType.None;
}
public override EditorPartCollection CreateEditorParts()
{
editorPart = new QuoteEditor();
editorPart.ID = this.ID + "_editList";
editorPart.Title = "Edit Quote";
EditorPartCollection parts =
new EditorPartCollection(new EditorPart[] { editorPart });
return parts;
}
/***************************************************************
* RENDER WEBPART
***************************************************************/
/// <summary>
/// Render web part
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
//nothing to render
if (String.IsNullOrEmpty(quote))
{
writer.Write("Please set the a qoute by editing this webpart.");
return;
}
RenderPart(writer);
}
private void RenderPart(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, "quotepart");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute(HtmlTextWriterAttribute.Src,"/library/images/marble_small.gif");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "quoteimage");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();//</img>
writer.AddAttribute(HtmlTextWriterAttribute.Class, "quotetext");
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(quote);
writer.RenderEndTag();//</label>
if (!string.IsNullOrEmpty(quoteauthor))
{
writer.WriteBreak();
writer.AddAttribute(HtmlTextWriterAttribute.Class, "quoteauthor");
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(quoteauthor);
writer.RenderEndTag();//</label>
}
writer.RenderEndTag();//</div>
}
}
}
AS YOU CAN SEE, I PUT THE EDITOR IN THE EditorPartCollection , SO YOU ARE SAYING NOT TO DO SO.
could you elaborate the code a bit more please, or just give me a coule more of directions, i will really appreaciatte so.
Cheers,
|
|
| |
Free Download:
|
Web:Completely Dynamic Webparts with drag-drop & ATLAS functionality ... Completely Dynamic Webparts with drag-drop & ATLAS functionality. Last post 02- 02-2008 1:24 PM by ErMasca. 14 replies. Sort Posts: ... Alessandro Gallo : Introduction to Drag And Drop with Atlas Ok, we are ready to make this a dynamic page by adding Atlas markup. ..... Hi, I 'm trying to implement drag and drop functionality for items in a scrollable ... ng.asp-net-forum.web_parts_and_personalization/6 - Fix error ... Completely Dynamic Webparts with drag-drop & ATLAS functionality, 14, 12, 2/2/ 2008 6:24:28 PM. Web Parts Help-Urgent, 3, 5, 2/2/2008 10:37:04 AM ... CodeProject: Dragging and dropping with ASP.NET 2.0 and Atlas ... Dynamic Drag Drop. Since the declarative model is much cleaner than the ...... I used webparts before but there are issue like referencing not working, ... DotNetSlackers: Introduction to Drag And Drop with Atlas Introduction to Drag And Drop with Atlas. Posted by: Atlas notes, on 17 Jan 2006 ... Then, we'll add dynamic behaviors to controls with some Atlas markup. ... A Continuous Learner's Weblog: October 2006 NET 2.0 Portal Framework) · Drag and drop ASP.NET 2.0 Web Parts in Firefox with Atlas · Completely Dynamic Web Parts with drag-drop & Atlas functionality ... Nikhil Kothari's Weblog : Atlas M2.2 - Dynamic UpdatePanels (finally) The June Atlas CTP fixes some bugs, and adds support for dynamic ... to use the drag Panel in one of my page which also contains some drop down lists. ... Working with Web Parts in ASP.NET 2.0 Jan 18, 2007 ... Neimke: Features such as Atlas and Web Parts are examples of how the ASP ... paradigm and add other common functionality, such as drag-drop, ... Safari Books Online - 0596526725 - Programming Atlas Atlas offers several ways to reuse components to add functionality to browser- based ... Web Parts are enabled using client script to support drag and drop, ... Page 1 Ajax at Work: Healthcare Provider’s Dashboard Doug Forst ... developer to integrate the Atlas functionality into the page. .... drag-and-drop or editing. Therefore, only one click works like it should before the ... |
|
Search This Site:
|
|