Late binding-OptionStrict

  • Thread starter Thread starter noone
  • Start date Start date
N

noone

I like to write my code with optionstrict set to on, except for the late
binding errors I get when there is a reason to change some value in a
control on a postback, like:
Label4.Text = (sender.CommandArgument).tostring

HiddenCreative.Value = sender.CommandArgument

that are in a onclick handler for a webform. Looking at the doc it looks
like the only option with OptionStrict is off or on. Is there a way to
simply have the compleir ignore the latebinding errors? I compile in VSNet
and do not use the command line. I grow weary of turning option strict on
and off.





x-- 100 Proof News - http://www.100ProofNews.com
x-- 3,500+ Binary NewsGroups, and over 90,000 other groups
x-- Access to over 800 Gigs/Day - $8.95/Month
x-- UNLIMITED DOWNLOAD
 
noone,
Option Strict On is used to disable Late Binding.
Label4.Text = (sender.CommandArgument).tostring

Seeing as sender is an Object, you are using Late Binding to get to
CommandArgument property.

If you want Option Strict On, which normally I do unless I want to do Late
Binding, you need to cast sender to Button, so that you can use its
property.

Sub CommandBtn_Click(sender As Object, e As CommandEventArgs)
Dim command As Button = DirectCast(sender, Button)
Label4.Text = command.CommandArgument.ToString()
End Sub

Alternatively you can use CommandArgument from the event args parameter.

Sub CommandBtn_Click(sender As Object, e As CommandEventArgs)
Label4.Text = e.CommandArgument.ToString()
End Sub

Hope this helps
Jay
 
Back
Top