473,545 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom controls and events

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

}
this.FirstLinkB utton.Command+= new
CommandEventHan dler(this.LinkB *utton_Command) ;
base.CreateChil dControls();
System.Web.UI.H tmlControls.Htm *lTable
htmlTbl=new
System.Web.UI.H tmlControls.Htm *lTable();
System.Web.UI.H tmlControls.Htm *lTableRow
htmlRow=new
System.Web.UI.H tmlControls.Htm *lTableRow();
System.Web.UI.H tmlControls.Htm *lTableCell
htmlCell;
htmlCell=new
System.Web.UI.H tmlControls.Htm *lTableCell();
htmlCell.Contro ls.Add(FirstLin *kButton);
htmlRow.Control s.Add(htmlCell) *;
htmlTbl.Control s.Add(htmlRow);
this.Controls.A dd(htmlTbl);
}
When I remove the function everything is fine. (No error)

What am I missing here?

Thank you,

Doron.

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

My CreateChildCont rols 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.CreateChi ldControls()) at the start of the method?

--
Jon Skeet - <sk***@pobox.co m>
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.A dd(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.InvalidC astException: 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:
[InvalidCastExce ption: Specified cast is not valid.]
System.Web.UI.W ebControls.Data Grid.PrepareCon trolHierarchy()
System.Web.UI.W ebControls.Base DataList.Render (HtmlTextWriter writer)
System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
System.Web.UI.H tmlControls.Htm lForm.RenderChi ldren(HtmlTextW riter
writer)

System.Web.UI.H tmlControls.Htm lContainerContr ol.Render(HtmlT extWriter
writer)
System.Web.UI.H tmlControls.Htm lForm.Render(Ht mlTextWriter output)
System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
System.Web.UI.C ontrol.RenderCh ildren(HtmlText Writer writer)
System.Web.UI.C ontrol.Render(H tmlTextWriter writer)
System.Web.UI.C ontrol.RenderCo ntrol(HtmlTextW riter writer)
System.Web.UI.P age.ProcessRequ estMain()

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.A dd(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.co m>
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
4756
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 Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For...
0
1121
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 function:
2
2213
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 am running into is that I cannot get the click event of this object handled. I have tried wiring the event with "AddHandler" among other things and...
1
2949
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 as it should: _myTemplateContainer = New ContentContainer(Me) ContentTemplate.InstantiateIn(_myTemplateContainer)...
1
2612
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 inside the server control when it is clicked on. however when I click on a button at present I get an error saying that the An error has occurred...
7
2975
by: Shimon Sim | last post by:
I have a custom composite control I have following property
19
4896
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom...
1
4772
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 Toolbox in Visual Web Developer 2005 Express Edition but the alert message isn't popping up when I am implementing this control in an ASP.NET page &...
0
1380
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' buttons. If the user clicks 'OK', the TextBox gets populated with 'true' & if 'Cancel' is clicked, the TextBox gets populated with 'false'. Note that...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6001
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...
1
5347
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...
0
4965
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...
0
3473
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...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
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

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.