In 3.5 adding an element in markup and referencing it via a property compiles fine:
<link id="lnkMainIE" runat="server" rel="stylesheet" type="text/css" />
public HtmlLink StyleMainIE { get { return lnkMainIE; } }
In 4, it gives the error Cannot implicitly convert type 'System.Web.UI.HtmlControls.HtmlGenericControl' to 'System.Web.UI.HtmlControls.HtmlLink'
If I declare my property as type HtmlGenericControl, I get the parser error at run time,
The base class includes the field 'lnkMain', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlLink)
If you add a link inside the "head" Content in a content page, this link is not a direct child under the <head> tag, but a child of the head <ContentPlaceHolder> tag. You will get an HtmlGenericControl in this case. There is no way to convert this to an
HtmlLink. This behavior has been existing since 2.0 AFAIK. You said it compiles in 3.5, did you use VS2008 and see it compile? I see the same behavior for both VS 2008 and VS 2010 for a 3.5 project.
Anh Phan
Marked as answer by dudeNumber4 on Feb 23, 2010 01:31 PM
dudeNumber4
Member
9 Points
31 Posts
Why does this compile in 3.5, but not 4?
Feb 11, 2010 05:10 PM|LINK
In 3.5 adding an element in markup and referencing it via a property compiles fine:
<link id="lnkMainIE" runat="server" rel="stylesheet" type="text/css" />
public HtmlLink StyleMainIE { get { return lnkMainIE; } }
In 4, it gives the error Cannot implicitly convert type 'System.Web.UI.HtmlControls.HtmlGenericControl' to 'System.Web.UI.HtmlControls.HtmlLink'
If I declare my property as type HtmlGenericControl, I get the parser error at run time, The base class includes the field 'lnkMain', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlLink)
Something seems amiss...
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 11, 2010 07:17 PM|LINK
I dont know the technical reason for the difference but it seems like its asking you to use the following format:
anhphan
Participant
863 Points
190 Posts
Microsoft
Re: Why does this compile in 3.5, but not 4?
Feb 18, 2010 06:13 PM|LINK
It works fine for me in both, 3.5 and 4.0. Are you using VS2010 RC? Do you put the link inside the <head> section?
dudeNumber4
Member
9 Points
31 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 02:38 PM|LINK
I'm placing it in a Content tag that references the head section in the master page. Doesn't compile in either Beta 2 or RC1.
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 09:12 PM|LINK
does the <head> tag in the masterpage have runat="server" on it?
anhphan
Participant
863 Points
190 Posts
Microsoft
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 10:19 PM|LINK
If you add a link inside the "head" Content in a content page, this link is not a direct child under the <head> tag, but a child of the head <ContentPlaceHolder> tag. You will get an HtmlGenericControl in this case. There is no way to convert this to an HtmlLink. This behavior has been existing since 2.0 AFAIK. You said it compiles in 3.5, did you use VS2008 and see it compile? I see the same behavior for both VS 2008 and VS 2010 for a 3.5 project.