How to pass a control optionally

Discussion in 'ASP .Net' started by eagle, Sep 2, 2005.

  1. eagle

    eagle Guest

    How can I pass a control to another procedure as an option?

    I tried:
    Call DoStuff(lbl)

    Private Sub DoStuff(Optional lnkbtn = nothing)

    if lnkbtn <> nothing then lnkbtn.visible = true

    end sub


    and I get an error saying Operator is not valid for type LinkButton and
    Nothing
    eagle, Sep 2, 2005
    #1
    1. Advertising

  2. eagle

    Siva M Guest

    Hi,

    Try DoStuff(Optional lnkbtn As Control = Nothing)

    "eagle" <> wrote in message
    news:%23E0Uan%...
    How can I pass a control to another procedure as an option?

    I tried:
    Call DoStuff(lbl)

    Private Sub DoStuff(Optional lnkbtn = nothing)

    if lnkbtn <> nothing then lnkbtn.visible = true

    end sub


    and I get an error saying Operator is not valid for type LinkButton and
    Nothing
    Siva M, Sep 2, 2005
    #2
    1. Advertising

  3. eagle

    Marina Guest

    1. Turn Option Strict On. Declare types for all your objects.
    2. If Not IsNothing(lnkbtn) Then lnkbtn.Visible = True

    "eagle" <> wrote in message
    news:%23E0Uan%...
    > How can I pass a control to another procedure as an option?
    >
    > I tried:
    > Call DoStuff(lbl)
    >
    > Private Sub DoStuff(Optional lnkbtn = nothing)
    >
    > if lnkbtn <> nothing then lnkbtn.visible = true
    >
    > end sub
    >
    >
    > and I get an error saying Operator is not valid for type LinkButton and
    > Nothing
    >
    Marina, Sep 2, 2005
    #3
  4. eagle

    Karl Seguin Guest

    Or, use overloading

    public sub DoStuff()
    DoStuff(nothing)
    end sub
    public sub DoStuff(byval control as Control)
    if not control is nothing then
    control.Visible = true
    end if
    end sub

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "eagle" <> wrote in message
    news:%23E0Uan%...
    > How can I pass a control to another procedure as an option?
    >
    > I tried:
    > Call DoStuff(lbl)
    >
    > Private Sub DoStuff(Optional lnkbtn = nothing)
    >
    > if lnkbtn <> nothing then lnkbtn.visible = true
    >
    > end sub
    >
    >
    > and I get an error saying Operator is not valid for type LinkButton and
    > Nothing
    >
    Karl Seguin, Sep 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Iam
    Replies:
    0
    Views:
    436
    Sam Iam
    Jan 31, 2004
  2. Kirill Simonov
    Replies:
    2
    Views:
    311
    =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=
    Oct 9, 2006
  3. Dilip
    Replies:
    5
    Views:
    384
  4. Mark Space
    Replies:
    3
    Views:
    619
    Daniel Pitts
    Sep 30, 2008
  5. Peter Alvin

    Optionally pass a parameter?

    Peter Alvin, Sep 23, 2008, in forum: Ruby
    Replies:
    1
    Views:
    93
    James Coglan
    Sep 23, 2008
Loading...

Share This Page