473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error rendering Custom Web Control in VS.NET ide

I developed a Date Picker web control using C# and .net framework 1.1
I added my control to Visual Studio 2003 IDE toolbar.
When I drag and drop my control to design web page, the control renders
correctly.
If I change to HTML the generated html is

<cc1:IT24DateTi me id="IT24DateTim e1" runat="server"
Type="Date"></cc1:IT24DateTim e>

.... and that works correctly.

The problem is when in design time I change some property of my
control.
For example I changed the control property "Type" from "Date" to
"DateTime". In design time is all right.
When I change to HTML appears the rendered html inside the web control
tag:

<cc1:IT24DateTi me id="IT24DateTim e1" runat="server" Type="Date">
<asp:TableRow >
<asp:TableCel l>
<asp:TextBox runat="server" Width="80px" CssClass="input Text"
ID="txtdate_IT2 4DateTime1" MaxLength="10"> </asp:TextBox>
</asp:TableCell>
<asp:TableCel l>
<asp:Image runat="server" ImageUrl="Image s/Calendar.gif"
OnClick="popUpC alendar(documen t.getElementByI d('txtdate_IT24 DateTime1'),
document.getEle mentById('txtda te_IT24DateTime 1'), 'mm/dd/yyyy');"
style="cursor:p ointer;"></asp:Image>
</asp:TableCell>
<asp:TableCel l>
<asp:DropDownLi st runat="server" CssClass="dropd own">
<asp:ListItem Selected="True" ></asp:ListItem>
<asp:ListItem Value="0">00:00 AM</asp:ListItem>
<asp:ListItem Value="1">01:00 AM</asp:ListItem>
<asp:ListItem Value="2">02:00 AM</asp:ListItem>
<asp:ListItem Value="3">03:00 AM</asp:ListItem>
<asp:ListItem Value="4">04:00 AM</asp:ListItem>
</asp:DropDownLis t>
</asp:TableCell>
</asp:TableRow>
</cc1:IT24DateTim e>

.... and when I run the application, generate duplicated controls.
My question is, how can I do to avoid the control doesn't render the
controls when I change somo property?
There exist any way to protect it?
I allways would like to see in html

<cc1:IT24DateTi me id="IT24DateTim e1" runat="server"
Type="Date"></cc1:IT24DateTim e>

Here is my web control:

/// <summary>
/// Summary description for TextBoxColumn.
/// </summary>
[DefaultProperty ("Text"),
ToolboxData("<{ 0}:IT24DateTime runat=server></{0}:IT24DateTim e>"),
ToolboxBitmapAt tribute(typeof( Calendar))]

public class IT24DateTime : Table
{
private string _imgDirectory = "Images/Calendar/";
public string ImageDirectory
{
set { _imgDirectory = value; }
}

private string _error_CssClass = string.Empty;
public string ErrorCssClass
{
get { return _error_CssClass ; }
set { _error_CssClass = value; }
}

private string _separator = string.Empty;
public string Separator
{
get { return _separator; }
set { _separator = value; }
}

private bool _requireValidat ion = false;
public bool RequireValidati on
{
get { return _requireValidat ion; }
set { _requireValidat ion = value; }
}

private string _dateFormat = "MM/dd/yyyy";
public string DateFormat
{
get { return _dateFormat; }
set { _dateFormat = value; }
}

private string _timeFormat = "hh:mm tt";
public string TimeFormat
{
get { return _timeFormat; }
set { _timeFormat = value; }
}

private string _dateCssClass = "inputText" ;
public string DateCssClass
{
set { _dateCssClass = value; }
}

private string _timeCssClass = "dropdown";
public string TimeCssClass
{
set { _timeCssClass = value; }
}

private string _calendarImage = "Images/Calendar.gif";
public string CalendarImage
{
get { return _calendarImage; }
set { _calendarImage = value; }
}

[
Bindable(true),
Category("Appea rance"),
Description("Ty pe of Control. Date and Time, Date, or Time.")
]
private Date_Control_Ty pe _date_Control_T ype =
Date_Control_Ty pe.DateTime;
public Date_Control_Ty pe Type
{
get { return _date_Control_T ype; }
set { _date_Control_T ype = value; }
}

private DateTime _value = DateTime.Now;
public DateTime Value
{
get
{
//Make sure the child controls are accessible
this.EnsureChil dControls();
if(Rows.Count>0 )
{
DateTime dt = new DateTime();
switch(_date_Co ntrol_Type)
{
case Date_Control_Ty pe.Date:
{
// Get Date Control from container table
TableCell tc = Rows[0].Cells[0];
TextBox date = (TextBox)tc.Con trols[0];
dt = Utilities.GetDa teTime(date.Tex t);
break;
}
case Date_Control_Ty pe.Time:
{
// Get Time Control from container table
TableCell tc = Rows[0].Cells[0];
DropDownList time = (DropDownList)t c.Controls[0];
dt =
DateTime.Now.Ad dHours(Convert. ToDouble(time.S electedValue));
break;
}
case Date_Control_Ty pe.DateTime:
{
// Get Date Control from container table
TableCell tc = Rows[0].Cells[0];
TextBox date = (TextBox)tc.Con trols[0];

// Get Time Control from container table
tc = Rows[0].Cells[2];
DropDownList time = (DropDownList)t c.Controls[0];

if(!time.Select edValue.Equals( string.Empty))
{
dt = Utilities.GetDa teTime(date.Tex t,time.Selected Value);
}
else
{
dt = Utilities.GetDa teTime(date.Tex t);
}
break;
}
}
return dt;
}
return DateTime.Now;
}
set
{
//Make sure the child controls are accessible
this.EnsureChil dControls();
_value = value;

if(Rows.Count>0 )
{
string strDate = _value.ToString (_dateFormat);
string strTime =
_value.AddMinut es(60-_value.Minute). ToString(_timeF ormat);

switch(_date_Co ntrol_Type)
{
case Date_Control_Ty pe.Date:
{
// Get Date Control from container table
TableCell tc = Rows[0].Cells[0];
TextBox date = (TextBox)tc.Con trols[0];
date.Text = strDate;
break;
}
case Date_Control_Ty pe.Time:
{
// Get Time Control from container table
TableCell tc = Rows[0].Cells[0];
DropDownList time = (DropDownList)t c.Controls[0];
setValueInDropd own(ref time, strTime);
break;
}
case Date_Control_Ty pe.DateTime:
{
// Get Date Control from container table
TableCell tc = Rows[0].Cells[0];
TextBox date = (TextBox)tc.Con trols[0];
date.Text = strDate;

// Get Time Control from container table
tc = Rows[0].Cells[2];
DropDownList time = (DropDownList)t c.Controls[0];
setValueInDropd own(ref time, strTime);

break;
}
}
}
}
}

protected override void OnPreRender(Eve ntArgs e)
{
if (!Page.IsClient ScriptBlockRegi stered("jsCalen dar"))
{
Page.RegisterCl ientScriptBlock ("jsCalendar ", placeJavascript ());
}
base.OnPreRende r(e);
}

protected override void Render(HtmlText Writer output)
{
// Render base object that contains all controls
if ((Context==null ) || ((Site != null) && Site.DesignMode ))
return;
base.Render(out put);
}

protected override void OnInit(EventArg s e)
{
TableRow tr = new TableRow();
TableCell tc;

//string date = _dateTime.ToStr ing(_dateFormat );
//string time =
_dateTime.AddMi nutes(60-_dateTime.Minut e).ToString(_ti meFormat);

if(_date_Contro l_Type.Equals(D ate_Control_Typ e.DateTime)
|| _date_Control_T ype.Equals(Date _Control_Type.D ate))
{
TextBox txtDate = new TextBox();
txtDate.ID = "txtdate_" + ID;
txtDate.MaxLeng th = 10;
txtDate.Width = Unit.Pixel(80);
txtDate.CssClas s = _dateCssClass;
//txtDate.Text = date;

tc = new TableCell();
tc.Controls.Add (txtDate);
tr.Cells.Add(tc );

Image imgCalendar = new Image();
imgCalendar.Ima geUrl = _calendarImage;
imgCalendar.Att ributes.Add("On Click",
"popUpCalendar( document.getEle mentById('" + txtDate.ID + "'),
document.getEle mentById('" + txtDate.ID + "'), '" +
_dateFormat.ToL ower() + "');");
imgCalendar.Sty le.Add("cursor" , "pointer");

tc = new TableCell();
tc.Controls.Add (imgCalendar);
tr.Cells.Add(tc );
}

if(_date_Contro l_Type.Equals(D ate_Control_Typ e.DateTime)
|| _date_Control_T ype.Equals(Date _Control_Type.T ime))
{
DropDownList cmbMinutes = new DropDownList();
cmbMinutes.CssC lass = _timeCssClass;
loadMinutes(ref cmbMinutes);
//setValueInDropd own(ref cmbMinutes, time);

tc = new TableCell();
tc.Controls.Add (cmbMinutes);
tr.Cells.Add(tc );
}

Rows.Add(tr);
}

Any support or help would be appreciated.
Thank you to everyone...
Regards,
Pablo
pa*********@gma il.com

Oct 12 '06 #1
0 1606

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3037
by: David Whitney | last post by:
All: I have a control that renders a table. As the table is rendered, each row in the table is constructed by creating a run-time (dynamic) object that is derived from an HtmlTableRow. The row has three HtmlTableCell objects, and each cell contains a single control added to the HtmlTableCell's Controls collection. The basic table renders correctly, but the controls within the HtmlTableCell objects do not; the cells are just empty. (Just...
0
1514
by: Steve R | last post by:
I've built a composite web custom control with a lot of child controls. I assigned ToolTip values to some of these controls. The ToolTip pop-ups were working fine until I monkeyed with the order I am rendering the controls. I had to do this so that the control rendered properly when a developer drags it from the toolbox onto the page. Any ideas? Below is the meat of the code from my user control. The remainder is private methods.
0
1219
by: Scott Yenor | last post by:
Hello, I am writing a control library that has a control that inherits from System.Web.UI.Control. The control works fine and I am able to loop through the child controls and display everything fine until I try to put some ASP.NET processing code in-between the tags. For example: This works fine. The control executes and displays everything just
0
975
by: Nikhil Patel | last post by:
Hi all. I have written a custom DataGrid control which inherits from ASP.Net DataGrid control. When I drop this control on an ASP.Net form, it does not display the grid properly. It says error rendering control. Do I need to do anything in my control so that it gets displayed just like the standard DataGrid at design time. This is my first custom ASP.Net control. So please help. Thanks... -Nikhil
0
1372
by: Sanjay Pais | last post by:
I have created a custom control that inherits from the textbox control and adds a property to it. When I drop it on a page it renders just fine. However, When I drop it into a web user control (ascx) and drop this user control on my page I get the error "Error Rendering Control" - AEPLabel1
5
2343
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a problem in this scenario: <myprefix:mycontrol runat="server"> <%= SomeVariable %> </myprefix:mycontrol>
1
2955
by: epatrick | last post by:
I have a series of custom controls developed under ASP.NET 1.1, and I've successfully migrated to ASP.NET 2.0. I have also developed a custom class dervied from System.Web.UI.Page, called qbo.Web.Page. All of these controls compile and run correctly under ASP.NET 2.0. However, several of these controls throw an error in the design mode of VS.NET 2005. Specifically, controls that include a property override of Page (to cast as a...
2
4240
by: Benton | last post by:
Hi there, I'm creating a custom server control, inheriting from TextBox. It has this AsDateTime property that returns the textbox contents converted to the nullable DateTime data type, as follows: public class TextBoxWeb : System.Web.UI.WebControls.TextBox {
2
5207
by: Chris | last post by:
I have created a custom composite control, which is a date picker. It works fine but in the design view I get am "Error creating control" 'caltext' could not be set on property 'btnCssClass' (caltext is the string I am assigning for the cssclass of a button on the control). I don't need it to display anything in design view, a blank grey box would be fine. It's just this error sometimes stop the whole page from rendering in design view. ...
0
1014
by: josh | last post by:
Hi, I've created a custom control that inherits form BaseValidator. It is in a class named: MaxChars. All the code run well but when I switch in Visual Studio from source in design view I have an error: error in creation (rendering) of control: Tag server my:MaxChars
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.