By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Custom controls and events

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.