PDA

View Full Version : حرفه ای: پیاده سازی اینترفیسIWebpart



zkazemi
یک شنبه 19 مهر 1388, 15:39 عصر
با سلام
من می خوام برای نمایش برخی از خصوصیات مربوط به web user control مثل title ,titleUrl و... اینترفیس Iwebpart رو پیاده سازی کنم ولی بعد از پیاده سازی بازهم با خطا مواجه شدم. که از پیاده سازی یکی از اعضا خطا گرفته بود. لطفا اگه کسی نحوه پیاده سازی این رابط رو میدونه لطفا کمکه کنه چون برای ساخت یه برنامه پرتال واقعا لازمه که هر usercontrol عنوان خودش رو داشته باشه وگرنه همه رو Untitled نشو ن میده .
لطفا کمک کنید .
با تشکر فراوان

golagha_program
یک شنبه 19 مهر 1388, 17:12 عصر
اول اين كلاس رو بنويس


public class BaseWebPart : UserControl, IWebPart
{
private string _catalogIconImageUrl = "";
public string CatalogIconImageUrl
{
get { return _catalogIconImageUrl; }
set { _catalogIconImageUrl = value; }
}

private string _description = "";
public string Description
{
get { return _description; }
set { _description = value; }
}

protected string _subTitle = "";
public string Subtitle
{
get { return _subTitle; }
set { _subTitle = value; }
}

protected string _title = "";
public string Title
{
get { return _title; }
set { _title = value; }
}

private string _titleIconImageUrl = "";
public string TitleIconImageUrl
{
get { return _titleIconImageUrl; }
set { _titleIconImageUrl = value; }
}

private string _titleUrl = "";
public string TitleUrl
{
get { return _titleUrl; }
set { _titleUrl = value; }
}
}

حالا هر usercontrolet بايد از اين ارث ببره

zkazemi
دوشنبه 11 آبان 1388, 15:36 عصر
خيلي ممنون اين كد رو تو help هم ديدم ولي از CatalogIconImageUrl خطا ميگيره .

jimjimy
شنبه 30 دی 1391, 18:32 عصر
چیزی که من نوشتم اینه :

public partial class Categories : System.Web.UI.UserControl, IWebPart
{
protected void Page_Load(object sender, EventArgs e)
{

}

private string catalogIconImageUrl;
public string CatalogIconImageUrl
{
get { return catalogIconImageUrl; }
set { catalogIconImageUrl = value; }
}


private string titleIconImageUrl;
public string TitleIconImageUrl
{
get { return titleIconImageUrl; }
set { titleIconImageUrl = value; }
}

private string titleUrl;
public string TitleUrl
{
get { return titleUrl; }
set { titleUrl = value; }
}

private string title;
public string Title
{
get { return (title == null) ? "Ctegories" : title; }
set { title = value; }
}

public string Subtitle
{
get { return "Information about our categories"; }
}

private string description;
public string Description
{
get { return description; }
set { description = value; }
}

}

jimjimy
شنبه 30 دی 1391, 18:49 عصر
بعد این که شما این Property ها رو تعریف کردی میری تو اون صفحه ای که User control رو Add کردی و سپس داخل تگه مورد نظرت <uc2:Categories ID="TheCategories" runat="server" OnLoad="TheCategories_Load" /> .
OnLoad="TheCategories_Load" این رو اضافه میکنی .
و سپس میری تو Cs همون صفحه که OnLoad رو اضافه کردی و این کدها رو با توجه به نیازت میزنی :(یعنی همان Property هایی که در بالا ایجاد کردیم.)

protected void TheCategories_Load(object sender, EventArgs e)
{
IWebPart webpart = TheCategories;
webpart.Title = "Product Categories";
webpart.TitleUrl = "http://www.totaltraining.com";
webpart.Description = "Click here for product categories.";
}

jimjimy
شنبه 30 دی 1391, 19:25 عصر
و سایر Property هایی که اضافه کردید .

jimjimy
یک شنبه 01 بهمن 1391, 08:12 صبح
Until now you have accessed web parts from the outside only. But when creating a user control that will
be used as a web part on a web part page, you can access properties of the web part from inside the user
control as well. To a certain degree, you can control the web part’s appearance and behavior in a more
detailed manner by implementing the IWebPart interface.

CatalogIconImageUrl : Gets or sets the URL toan image displayed for the web part in the
PageCatalogPart of a CatalogZone.
Description : Gets or sets a string that contains a user-friendly description of the web
part.
Subtitle : Specifies the user-friendly subtitle of the web part. This one is
concatenated with the title contained in the Title property of the web part.
Title : Specifies a title displayed for the web part. With this property specified,
you don’t need to set the title fromoutside, as previously described.
TitleIconImageUrl: URL that points to an image displayed as an icon within the title bar of the
web part.
TitleUrl : Specifies the URL to which the browser should navigate when the user
clicks the title of the web part. If this URL is set, the title renders as a link;
otherwise, the title renders as static text.