|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VS2003 to VS2005 ConversionI am in the process of converting a VS 2003 project to VS 2005 project (VB.NET Class Library). It gives the error in TypeOf and DirectCast statements. It was working perfectly under VS2003. Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) If TypeOf ctl Is DropDownList Then DirectCast(ctl, DropDownList).Items.Clear() End If End Sub 1) The error is Expression of type 'System.Web.UI.HtmlControls.HtmlControl' can never be of type 'System.Web.UI.WebControls.DropDownList'. 2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot be converted to 'System.Web.UI.WebControls.DropDownList' How I can avoid these errors, I tried changing the Option Strict option to Off. I cannot change the code because the TypeOf and DirectCast statements are used in more than 200 places. Thanks & Regards, Sam
Show quote
Hide quote
"Samuel" <sam***@photoninfotech.com> schrieb DropDownList is not derived from HtmlControl, thus you can not cast this > Hi All, > > > > I am in the process of converting a VS 2003 project to VS 2005 > project (VB.NET Class Library). > > > > It gives the error in TypeOf and DirectCast statements. It was > working perfectly under VS2003. > > > > Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) > > If TypeOf ctl Is DropDownList Then > > DirectCast(ctl, DropDownList).Items.Clear() > > End If > > End Sub > > > > 1) The error is Expression of type > 'System.Web.UI.HtmlControls.HtmlControl' can never be of type > 'System.Web.UI.WebControls.DropDownList'. > > 2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot > be converted to 'System.Web.UI.WebControls.DropDownList' > > > > How I can avoid these errors, I tried changing the Option Strict > option to Off. I cannot change the code because the TypeOf and > DirectCast statements are used in more than 200 places. way. Why do you think you can? A HtmlControl does not have an Items property. The classes derived from HtmlControl are System.Web.UI.HtmlControls.HtmlContainerControl System.Web.UI.HtmlControls.HtmlImage System.Web.UI.HtmlControls.HtmlInputControl ctl can point to one of these objects, but /never/ to a DropDownList object. Armin But it was working in VS2003. Is it possible to make the code to work in
VS2005 ? Show quoteHide quote "Armin Zingler" <az.nospam@freenet.de> wrote in message news:%23Q7a9e3FGHA.2064@TK2MSFTNGP09.phx.gbl... > "Samuel" <sam***@photoninfotech.com> schrieb >> Hi All, >> >> >> >> I am in the process of converting a VS 2003 project to VS 2005 >> project (VB.NET Class Library). >> >> >> >> It gives the error in TypeOf and DirectCast statements. It was >> working perfectly under VS2003. >> >> >> >> Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) >> >> If TypeOf ctl Is DropDownList Then >> >> DirectCast(ctl, DropDownList).Items.Clear() >> >> End If >> >> End Sub >> >> >> >> 1) The error is Expression of type >> 'System.Web.UI.HtmlControls.HtmlControl' can never be of type >> 'System.Web.UI.WebControls.DropDownList'. >> >> 2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot >> be converted to 'System.Web.UI.WebControls.DropDownList' >> >> >> >> How I can avoid these errors, I tried changing the Option Strict >> option to Off. I cannot change the code because the TypeOf and >> DirectCast statements are used in more than 200 places. > > DropDownList is not derived from HtmlControl, thus you can not cast this > way. Why do you think you can? A HtmlControl does not have an Items > property. The classes derived from HtmlControl are > > System.Web.UI.HtmlControls.HtmlContainerControl > System.Web.UI.HtmlControls.HtmlImage > System.Web.UI.HtmlControls.HtmlInputControl > > ctl can point to one of these objects, but /never/ to a DropDownList > object. > > > > Armin "Samuel" <sam***@photoninfotech.com> schrieb: I doubt that the code works in VS.NET 2003. The inheritance hierarchy > But it was working in VS2003. Is it possible to make the code to work in > VS2005 ? didn't change. Maybe you forgot to turn on 'Option Strict' in VS.NET 2003? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Hi,
Attached herewith the 2003 project files and 2005 project files. Now I think you will agree that the code will compile with 2003 and not with 2005. Sam Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message [attached file: 2005ClassLibrary2.zip]news:Ok1fgq3FGHA.3856@TK2MSFTNGP12.phx.gbl... > "Samuel" <sam***@photoninfotech.com> schrieb: >> But it was working in VS2003. Is it possible to make the code to work in >> VS2005 ? > > I doubt that the code works in VS.NET 2003. The inheritance hierarchy > didn't change. Maybe you forgot to turn on 'Option Strict' in VS.NET > 2003? > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > [attached file: 2003ClassLibrary2.zip] "Samuel" <sam***@photoninfotech.com> schrieb: I've never said the code won't compile in VS.NET 2003. I only said it won't > Attached herewith the 2003 project files and 2005 project files. Now I > think > you will agree that the code will compile with 2003 and not with 2005. work as expected. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Samuel" <sam***@photoninfotech.com> schrieb Have you tried it in VS2003? I'm pretty sure it does not work.> But it was working in VS2003. Is it possible to make the code to > work in VS2005 ? Armin Armin,
> Did you try it, I tried it there was no error given.> Have you tried it in VS2003? I'm pretty sure it does not work. > web.ui.htmlcontrols derive from web.ui.controls And than I stopped because there is a lot possible as well with html control however AFAIK not so well documented. Therefore I am currious if you have checked it really deep.. .. Cor "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb No. To check this, looking at the object browser should be sufficient. :-) I > > > > Have you tried it in VS2003? I'm pretty sure it does not work. > > > Did you try it, was not able to test it because I failed in assigning a DropDownList to a variable declared as HtmlControl. > I tried it there was no error given. Right. Inheritance hierarchiy:> web.ui.htmlcontrols derive from web.ui.controls System.Web.UI.HtmlControls.HtmlControl System.Web.UI.Control System.Web.UI.WebControls.DropDownList System.Web.UI.WebControls.ListControl System.Web.UI.WebControls.WebControl System.Web.UI.Control As you see, you can not cast HtmlControls.HtmlControl to DropDownList because DropDownList is not derived from HtmControl. > And than I stopped because there is a lot possible as well with html Yes, I checked the object browser really deep.> control however AFAIK not so well documented. Therefore I am > currious if you have checked it really deep.. Armin "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb I forgot: How did you try it?> Did you try it, I tried it there was no error given. Armin I just dragged the coded in a webproject (2003) and it did give no error.
Than I pushed F1 (not serious I have searched for it on MSDJ) and saw that they both derive from ui.web.control however "items" is not a direct member from that and that did confuse me. However to test this I would have to do as I wrote and that confuses me every time even more.. Cor "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb What's your conclusion now?> I just dragged the coded in a webproject (2003) and it did give no > error. > > Than I pushed F1 (not serious I have searched for it on MSDJ) and > saw that they both derive from ui.web.control however "items" is not > a direct member from that and that did confuse me. However to test > this I would have to do as I wrote and that confuses me every time > even more.. Armin > As written by you and Herfried, what can I conclude more.> What's your conclusion now? > Cor "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: I didn't try it, but I am sure the problem is that the warning is simply >> Have you tried it in VS2003? I'm pretty sure it does not work. > > Did you try it, I tried it there was no error given. missing in VS.NET 2003 and thus the code compiles but doesn't work as expected because the 'TypeOf...Is' condition is never met. VB 7.* lets you write and compile \\\ Dim f As Form If TypeOf f Is String Then MsgBox("Bla") End If /// although the condition will never be true because a variable of type 'Form' cannot reference a 'String' object. > web.ui.htmlcontrols derive from web.ui.controls Both are namespaces, so there is no "is-a" relation between them at all. As said in other messages, 'HtmlControl' is not derived from 'WebControl' and vice versa. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Samuel,
PMFJI. | But it was working in VS2003. Compiling yes, working (aka executing) we all doubt it!| Is it possible to make the code to work in No, for the reasons stated.| VS2005 ? Did the Items.Clear method in VS2003 ever get called for a DropDownList? Have you walked through your code in VS 2003 & verified the code (inside the If) actually executes? I suspect in VS2003 you effectively had: Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) End Sub i.e. Although the code compiles in VS 2003, the statement never executed as ctl could never be a DropDownList! VS 2005 is much better at catching coding errors such as this, that may appear correct when you type them, however the code won't actually execute. -- Show quoteHide quoteHope this helps Jay [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Samuel" <sam***@photoninfotech.com> wrote in message news:e6VTxm3FGHA.3200@tk2msftngp13.phx.gbl... | But it was working in VS2003. Is it possible to make the code to work in | VS2005 ? | | "Armin Zingler" <az.nospam@freenet.de> wrote in message | news:%23Q7a9e3FGHA.2064@TK2MSFTNGP09.phx.gbl... | > "Samuel" <sam***@photoninfotech.com> schrieb | >> Hi All, | >> | >> | >> | >> I am in the process of converting a VS 2003 project to VS 2005 | >> project (VB.NET Class Library). | >> | >> | >> | >> It gives the error in TypeOf and DirectCast statements. It was | >> working perfectly under VS2003. | >> | >> | >> | >> Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) | >> | >> If TypeOf ctl Is DropDownList Then | >> | >> DirectCast(ctl, DropDownList).Items.Clear() | >> | >> End If | >> | >> End Sub | >> | >> | >> | >> 1) The error is Expression of type | >> 'System.Web.UI.HtmlControls.HtmlControl' can never be of type | >> 'System.Web.UI.WebControls.DropDownList'. | >> | >> 2) Value of type 'System.Web.UI.HtmlControls.HtmlControl' cannot | >> be converted to 'System.Web.UI.WebControls.DropDownList' | >> | >> | >> | >> How I can avoid these errors, I tried changing the Option Strict | >> option to Off. I cannot change the code because the TypeOf and | >> DirectCast statements are used in more than 200 places. | > | > DropDownList is not derived from HtmlControl, thus you can not cast this | > way. Why do you think you can? A HtmlControl does not have an Items | > property. The classes derived from HtmlControl are | > | > System.Web.UI.HtmlControls.HtmlContainerControl | > System.Web.UI.HtmlControls.HtmlImage | > System.Web.UI.HtmlControls.HtmlInputControl | > | > ctl can point to one of these objects, but /never/ to a DropDownList | > object. | > | > | > | > Armin | |
Show quote
Hide quote
"Samuel" <sam***@photoninfotech.com> schrieb: Which is true. 'DropDownList' does not inherit from 'HtmlControl', not even >I am in the process of converting a VS 2003 project to VS 2005 project >(VB.NET Class Library). > >It gives the error in TypeOf and DirectCast statements. It was working >perfectly under VS2003. > >Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) > If TypeOf ctl Is DropDownList Then > DirectCast(ctl, DropDownList).Items.Clear() > End If >End Sub > >1) The error is Expression of type >'System.Web.UI.HtmlControls.HtmlControl' > can never be of type 'System.Web.UI.WebControls.DropDownList'. in .NET 1.1. You may want to use 'WebControls.WebControl' instead of 'HtmlControls.HtmlControl'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
I'm interested in how you think this could have been working perfecting for the OP under VS2003. Kerry Moorman Show quoteHide quote "Herfried K. Wagner [MVP]" wrote: > "Samuel" <sam***@photoninfotech.com> schrieb: > >I am in the process of converting a VS 2003 project to VS 2005 project > >(VB.NET Class Library). > > > >It gives the error in TypeOf and DirectCast statements. It was working > >perfectly under VS2003. > > > >Public Shared Sub Clear(ByVal ctl As HtmlControls.HtmlControl) > > If TypeOf ctl Is DropDownList Then > > DirectCast(ctl, DropDownList).Items.Clear() > > End If > >End Sub > > > >1) The error is Expression of type > >'System.Web.UI.HtmlControls.HtmlControl' > > can never be of type 'System.Web.UI.WebControls.DropDownList'. > > Which is true. 'DropDownList' does not inherit from 'HtmlControl', not even > in .NET 1.1. You may want to use 'WebControls.WebControl' instead of > 'HtmlControls.HtmlControl'. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > > "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> schrieb: That's what I am wondering about too.> I'm interested in how you think this could have been working perfecting > for > the OP under VS2003. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Email attachments?
Module and Class Option Strict Probably an intro question -> starting window over? calling form_load? Copying DataRows to another DataTable win32 dll vb.net pointers receiving data - HELP MDI's Declaring Variables Within a If Steatement Open pdf file with button in VB 2005 Locking Application to HDD Sr.No. |
|||||||||||||||||||||||