Hi,
I am doing some R&D on generating WebParts programatically. I am using
C# as my code behind language. I have 8 different zones on my page
which initially does not contain any WebParts. I have the following
class which i have derived from WebParts.
------------------------------------------------------------------------\
-------------------------------------------------------
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;
/// <summary>
/// Summary description for MyWebManager
/// </summary>
public class MyWebManager : WebPart
{
public string m_str;
public static int instanceCount=0;
public MyWebManager()
{
//comment to allow close
this.AllowClose = false;
this.AllowEdit = true;
this.AllowZoneChange = true;
this.EnableViewState = true;
AppDomain CurAppDomain = AppDomain.CurrentDomain;
m_str = CurAppDomain.GetData("APP_NAME").ToString();
instanceCount++;
}
public MyWebManager(String Title):base()
{
this.Title = Title;
this.AllowClose = false;
}
protected override void CreateChildControls()
{
try
{
this.Controls.Clear();
TextBox DisplayContent = new TextBox();
DisplayContent.Text = m_str;
this.Controls.Add(DisplayContent);
this.ChildControlsCreated = true;
}
catch (Exception ex)
{
}
finally
{
}
}
}
------------------------------------------------------------------------\
-------------------------------------------------------
now i am using this class to create webnparts dynamically on my wb page
as follows,
------------------------------------------------------------------------\
--------------------------------------------------------
AppDomain currentDomain = AppDomain.CurrentDomain;
//set predefined system variable application name
String dataName = "APP_NAME";
String setappname = "TestingApplication";
currentDomain.SetData(dataName, setappname);
try
{
MyWebMAnager myPart = new MyWebManager("MyPart" +
i.ToString());
WebPartManager1.AddWebPart(myPart, WebPartZone8, (100 +
i));
}
catch (Exception ex)
{
}
------------------------------------------------------------------------\
-------------------------------------------------------
The above code is working fine but every time the page is posted back
it creates the new instance of webpart in zone8 [:(] . Can Any one
help me
out how i can stop this. I want to create the object of webpart if it
is not on page else the programm should not generate the web part.. :).
Thanx in advance. [:)]
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNet2/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/