dotSITE
Шаблоны проектирования Work in Murano Software. Вопросы/Ответы
новости материалы решения форумы группы настройки/о проекте

Автор: Сергеев Арсений
Тема: Помогайте с серверным контролом
Дата: 4/19/2007 5:57:00 PM
Есть система XP_64 + IIS_6 + .net_framework_3(asp.net 2.0.50727)

Задача сделать серверный контрол, которому на aspx-страницах можно будет декларативно передавать массив параметров.
Например так:

[code]
<%@ Register Src="~/IllustratorControl.ascx" TagName="Illustrator" TagPrefix="ucc" %\>
...
<ucc:Illustrator runat="server"\>
      <ucc:IllustratorItem path="filename1" summary="qwerty1" />
      <ucc:IllustratorItem path="filename2" summary="qwerty2" />
   </ucc:Illustrator>
[/code]

Причём на каждой странице кол-во параметров разное. Основное тело контрола, отвечающее за визуализацию находиться в ascx-файле.
В msdn я нашол соответствующую тему <a>http://msdn2.microsoft.com/en-us/library/aa720381(VS.71).aspx</a>
И статью на русском по серверным контролам, которая суть есть перевод msdn.
Делал все по инструкции:
1)В code-behind файле
[code]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

//класс свойства по умолчанию
public class IllustratorItem
{
   string _path;
   string _summary;

   public string path
   {
      get { return this._path; }
      set { this._path = value; }
   }
   public string summary
   {
      get { return this._summary; }
      set { this._summary = value; }
   }

   public IllustratorItem() : this("", "")    { }
   public IllustratorItem(string ppath, string psummary)
   {
      this._path = ppath;
      this._summary = psummary;
   }
}
//класс контрола с определенным ParseChildren
[ParseChildren(true, "IllustratorItems")]
public partial class IllustratorControl : System.Web.UI.UserControl
{
   ArrayList items;

   public ArrayList IllustratorItems
   {
      get { return this.items; }
      set { this.items = value; }
   }

   protected void Page_Load(object sender, EventArgs e) { }
}
[/code]

2) ascx файл пока вообще не трогаю.
[code]
&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="IllustratorControl.ascx.cs" Inherits="IllustratorControl" %&gt;
[/code]
При компиляции на странице aspx, куда я вставил контрол выдается ошибка - "Parser Error Message: Object reference not set to an instance of an object."
[Source Error]
&lt;ucc:IllustratorItem path="filename1" summary="qwerty1" /&gt;
&lt;ucc:IllustratorItem path="filename2" summary="qwerty2" /&gt;
[/Source Error]





 ASP.NET -- Программирование на ASP.NET
 Помогайте с серверным контролом Сергеев Арсений    4/19/2007 5:57:00 PM


Контакт Реклама на сайте Спонсорам Веб мастерам

Лицензионное соглашение - © 2000-2012 dotSITE
Хостинг .NET предоставлен PARKING.RU
Поддержку сайта осуществляет Murano Software Inc., Offshore software development