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.
Member
6 Points
30 Posts
Why does this compile in 3.5, but not 4?
Feb 11, 2010 01:10 PM|dudeNumber4|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...
All-Star
39486 Points
8916 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 11, 2010 03:17 PM|rtpHarry|LINK
I dont know the technical reason for the difference but it seems like its asking you to use the following format:
Member
482 Points
190 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 18, 2010 02:13 PM|anhphan|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?
Member
6 Points
30 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 10:38 AM|dudeNumber4|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.
All-Star
39486 Points
8916 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 05:12 PM|rtpHarry|LINK
does the <head> tag in the masterpage have runat="server" on it?
Member
482 Points
190 Posts
Re: Why does this compile in 3.5, but not 4?
Feb 22, 2010 06:19 PM|anhphan|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.