Ciao a tutti
ho creato il mio primo controllo personalizzato:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BasicFrame.WebControls;
namespace controlliWeb
{
//[DefaultProperty("Text")]
[ToolboxData("<{0}:formRicerca runat=server></{0}:formRicerca>")]
public class formRicerca : WebControl
{
BasicFrame.WebControls.BasicDatePicker txtDal, txtAl;
DropDownList ddlNumeroCamere;
Label lblDal, lblAl;
BasicFrame.WebControls.DateDifferenceValidator ddvDal;
Table tbRicerca;
protected override void CreateChildControls()
{
this.Controls.Clear();
tbRicerca = new Table();
tbRicerca.CellPadding = 2;
tbRicerca.CellSpacing = 2;
tbRicerca.Width = Unit.Pixel(368);
TableRow trPeriodo = new TableRow();
TableCell tdPeriodo = new TableCell();
tdPeriodo.ColumnSpan = 3;
lblDal = new Label();
lblDal.Text = "Dal ";
lblAl = new Label();
lblAl.Text = "Al ";
txtDal = new BasicFrame.WebControls.BasicDatePicker();
txtDal.TextBoxColumns = 8;
txtDal.DateFormat = "dd/MM/yyyy";
txtDal.TextBoxStyle.CssClass = "text_Box";
txtAl = new BasicFrame.WebControls.BasicDatePicker();
txtAl.TextBoxColumns = 8;
txtAl.DateFormat="dd/MM/yyyy";
txtAl.TextBoxStyle.CssClass = "text_Box";
ddvDal = new BasicFrame.WebControls.DateDifferenceValidator();
ddvDal.ErrorMessage = "*";
ddvDal.ToolTip = "La data inserita dev'essere precedente alla data del campo Al";
ddvDal.ControlToCompare = "txtAl";
ddvDal.ControlToValidate = "txtDal";
ddvDal.Difference = 1;
ddvDal.Operator = ValidationCompareOperator.GreaterThanEqual;
ddvDal.ValidationGroup="vgRicerca";
tdPeriodo.Controls.Add(lblDal);
tdPeriodo.Controls.Add(txtDal);
tdPeriodo.Controls.Add(ddvDal);
tdPeriodo.Controls.Add(lblAl);
tdPeriodo.Controls.Add(txtAl);
trPeriodo.Cells.Add(tdPeriodo);
tbRicerca.Rows.Add(trPeriodo);
TableRow trIntestazione = new TableRow();
TableCell tdIntestazione = new TableCell();
tdIntestazione.Controls.Add(new LiteralControl("n° camere"));
tdIntestazione.HorizontalAlign = HorizontalAlign.Right;
trIntestazione.Cells.Add(tdIntestazione);
tdIntestazione = new TableCell();
tdIntestazione.Controls.Add(new LiteralControl("adulti"));
tdIntestazione.HorizontalAlign = HorizontalAlign.Center;
trIntestazione.Cells.Add(tdIntestazione);
tdIntestazione = new TableCell();
tdIntestazione.Controls.Add(new LiteralControl("bambini"));
tdIntestazione.HorizontalAlign = HorizontalAlign.Center;
trIntestazione.Cells.Add(tdIntestazione);
tbRicerca.Rows.Add(trIntestazione);
for(int i=1; i<6; i++)
{
TableRow trCamere = new TableRow();
TableCell tdCamere = new TableCell();
if(i==1)
{
ddlNumeroCamere = new DropDownList();
ddlNumeroCamere.CssClass = "text_Box";
for(int j=1;j<6;j++)
ddlNumeroCamere.Items.Add(new ListItem(j.ToString(),j.ToString()));
tdCamere.Controls.Add(ddlNumeroCamere);
}
else
{
Label lbl = new Label();
lbl.Text = "Camera " + i.ToString();
tdCamere.Controls.Add(lbl);
}
trCamere.Cells.Add(tdCamere);
tdCamere = new TableCell();
DropDownList ddlAdulti = new DropDownList();
ddlAdulti.CssClass = "text_Box";
ddlAdulti.ID = "txtAdulti" + i.ToString();
for(int k=0;k<11;k++)
ddlAdulti.Items.Add(new ListItem(k.ToString(),k.ToString()));
tdCamere.Controls.Add(ddlAdulti);
trCamere.Cells.Add(tdCamere);
tdCamere = new TableCell();
DropDownList ddlBambini = new DropDownList();
ddlBambini.CssClass = "text_Box";
ddlBambini.ID = "txtBambini" + i.ToString();
for (int h = 0; h < 11; h++)
ddlBambini.Items.Add(new ListItem(h.ToString(), h.ToString()));
tdCamere.Controls.Add(ddlBambini);
trCamere.Cells.Add(tdCamere);
tbRicerca.Rows.Add(trCamere);
}
this.Controls.Add(tbRicerca);
}
protected override void RenderContents(HtmlTextWriter output)
{
tbRicerca.RenderControl(output);
}
}
}
Quando inserisco il controllo in una pagina ricevo questo se visualizzo la pagina in progettazione:
Errore di rendering del controllo - FormRicerca1
Eccezione non gestita
Riferimento ad un oggetto non impostato su un istanza di oggetto
Dove sbaglio?
Grazie mille