473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Custom controls and events

Hi,
I'm tryig to add a LinkButton with events to a custom control (custom
control : Datagrid)
My CreateChildControls is generating an error (Specified cast is not
valid.)
Here is my function:
protected override void CreateChildControls()
{
if(FirstLinkButton==null)
{
FirstLinkButton=new Button();
FirstLinkButton.Text="<<";
FirstLinkButton.CommandName="F*irst";
FirstLinkButton.ID="FirstLinkB*utton";

}
this.FirstLinkButton.Command+= new
CommandEventHandler(this.LinkB*utton_Command);
base.CreateChildControls();
System.Web.UI.HtmlControls.Htm*lTable
htmlTbl=new
System.Web.UI.HtmlControls.Htm*lTable();
System.Web.UI.HtmlControls.Htm*lTableRow
htmlRow=new
System.Web.UI.HtmlControls.Htm*lTableRow();
System.Web.UI.HtmlControls.Htm*lTableCell
htmlCell;
htmlCell=new
System.Web.UI.HtmlControls.Htm*lTableCell();
htmlCell.Controls.Add(FirstLin*kButton);
htmlRow.Controls.Add(htmlCell)*;
htmlTbl.Controls.Add(htmlRow);
this.Controls.Add(htmlTbl);
}
When I remove the function everything is fine. (No error)

What am I missing here?

Thank you,

Doron.

Nov 17 '05 #1
3 2920
doron <do*****@amdocs.com> wrote:
I'm tryig to add a LinkButton with events to a custom control (custom
control : Datagrid)

My CreateChildControls is generating an error (Specified cast is not
valid.)


What line does it say the error is occurring on?

Have you tried calling the base implementation
(base.CreateChildControls()) at the start of the method?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
I tryde to move the base.Create... and got the same result.

In debug I'm reaching the last row ( this.Controls.Add(htmlTbl); ) and
only after it the error apears.

this is the full error: (no row number)

Server Error in '/Tests' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not
valid.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
System.Web.UI.WebControls.DataGrid.PrepareControlH ierarchy()
System.Web.UI.WebControls.BaseDataList.Render(Html TextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.HtmlControls.HtmlForm.RenderChildren (HtmlTextWriter
writer)

System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter
writer)
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTex tWriter output)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()

Nov 17 '05 #3
doron <do*****@amdocs.com> wrote:
I tryde to move the base.Create... and got the same result.

In debug I'm reaching the last row ( this.Controls.Add(htmlTbl); ) and
only after it the error apears.

this is the full error: (no row number)


<snip>

I don't know then, I'm afraid. I suggest you ask in the ASP.NET group,
preferrably with a short but complete example which demonstrates the
problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

4
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event...
0
by: doron | last post by:
Hi, I'm tryig to add a LinkButton with events to a custom control (custom control : Datagrid) My CreateChildControls is generating an error (Specified cast is not valid.) Here is my...
2
by: Juan Romero | last post by:
Hey guys, I am working on a web custom control that basically draws a table (ASP Table) with a few child controls in the cells. I have a command button inside one of these cells. The problem I...
1
by: news.microsoft.com | last post by:
If I have an ASP.net button inside a template for a custom control and use the code below, everything works fine and it generates the correct id and the asp.net button calls serverside click event...
1
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
1
by: rn5a | last post by:
I have created a custom control button which when clicked displays a message in the JavaScript alert dialog. I could successfully compile the VB class file into a DLL & also could add it to the...
0
by: rn5a | last post by:
A custom control is derived from the WebControl class & encapsulates a TextBox & a Button. When the Button is clicked, the user is shown the JavaScript confirm dialog with the 'OK' & 'Cancel'...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.