Late binding-OptionStrict

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • noone

    #1

    Late binding-OptionStrict

    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.Command Argument).tostr ing

    HiddenCreative. Value = sender.CommandA rgument

    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

  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Late binding-OptionStrict

    noone,
    Option Strict On is used to disable Late Binding.
    [color=blue]
    > Label4.Text = (sender.Command Argument).tostr ing[/color]

    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_Clic k(sender As Object, e As CommandEventArg s)
    Dim command As Button = DirectCast(send er, Button)
    Label4.Text = command.Command Argument.ToStri ng()
    End Sub

    Alternatively you can use CommandArgument from the event args parameter.

    Sub CommandBtn_Clic k(sender As Object, e As CommandEventArg s)
    Label4.Text = e.CommandArgume nt.ToString()
    End Sub

    Hope this helps
    Jay


    "noone" <no@one.com> wrote in message
    news:3fb5f016_1 @Opticon.100Pro ofNews.com...[color=blue]
    > 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.Command Argument).tostr ing
    >
    > HiddenCreative. Value = sender.CommandA rgument
    >
    > 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
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Late binding-OptionStrict

      noone,
      Option Strict On is used to disable Late Binding.
      [color=blue]
      > Label4.Text = (sender.Command Argument).tostr ing[/color]

      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_Clic k(sender As Object, e As CommandEventArg s)
      Dim command As Button = DirectCast(send er, Button)
      Label4.Text = command.Command Argument.ToStri ng()
      End Sub

      Alternatively you can use CommandArgument from the event args parameter.

      Sub CommandBtn_Clic k(sender As Object, e As CommandEventArg s)
      Label4.Text = e.CommandArgume nt.ToString()
      End Sub

      Hope this helps
      Jay


      "noone" <no@one.com> wrote in message
      news:3fb5f016_1 @Opticon.100Pro ofNews.com...[color=blue]
      > 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.Command Argument).tostr ing
      >
      > HiddenCreative. Value = sender.CommandA rgument
      >
      > 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
      >[/color]


      Comment

      Working...