Friday, March 16, 2012

option strict and late binding

Hi,

I'm trying to improve the performance of my web application every bit I can by compiling it with OptionStrict=On

I'm getting the error

Error 1 Option Strict On disallows late binding. C:\Inetpub\wwwroot\webapp1\create.aspx 52

All I am doing is binding to a repeater. Here is the repeater code.

Are repeaters not allowed in this fashion ? How can I compile my code with option strict on?

Thanks very much!

mike123

<asp:RepeaterID="repeaterNewsletters"runat="server"><ItemTemplate><b><%# Container.DataItem("newsletterID") %>.</b><ahref="preview.aspx?newsletterID=<%# Container.DataItem("newsletterID") %>"target="_blank"><%# Container.DataItem("dateSend") %></a>

<ahref="delete_newsletter.aspx?newsletterID=<%# Container.DataItem("newsletterID") %>">Delete</a><br/><br/></ItemTemplate></asp:Repeater>


Late Binding is different from Data Binding.

It simply mean strict type checking: strict type checking is all about declaring your variables to their
actual type (to the extent possible), no casting / conversions required.

Here is one similar thread, please check if your project has similar code

http://www.velocityreviews.com/forums/t80461-option-strict-on-disallows-late-binding.html


Hi George,

How would I fix this problem? I was able to fix all my other late binding problems by declaring the variables but I am having this problem because I am not sure how I am supposed to declare the variables on the databind?

The code in the example isn't really too similar. Basically I understand the late binding concept for everything I have encountered so far, but not when binding to a repeater.


Thanks very much!!

mike123


anybody have a clue on this ? Its a tough one to google suprisingly .. dieing to compile here =[

thanks again! :)

mike123


try replacing your calls to Container.DataItem with a call to Eval.

I.E.

<%#Eval("newsletterID")%>

Hi Mike,


Thanks for the suggestion, I did try that but to no prevail. Any other ideas much appreciated!

Regards,

mike123


i was able to successfully compile your code under option strict by using Eval.
I had no datasource to test with though...

What was your result?


Hey Mike, My bad, I thought it was the same as databinder.eval

<%# Eval("mediaID") %> appears to be working perfectly. I have a few hundred errors to fix so I'll have to see how it goes.

Could you explain what the difference is ? I'd love to know why one is working and the other isn't. You have no idea how much I appreciate this. I have a full days work of converting projects riddled with these error.

thanks again!

mike123


here's some details

http://msdn2.microsoft.com/en-us/library/ms178366.aspx

0 comments:

Post a Comment