Results 1 to 5 of 5

Thread: how to reference a control in a procedure (class)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    how to reference a control in a procedure (class)

    I have a web site with 20 web pages ,

    1) Each page has one has a Standard button bar with 5 buttons ( ADD, EDIT, DELETE, VIEW , EXIT), buttons will be visible or invisible depending on the operations being done.

    The above operation is universal for all the pages.

    How do i write a class with methods to make the above operation universal? I want to put this class in app_code directory .


    I Tried to put classes in app_code. but unable to hide show buttons of the individual page.I get a message "Object reference not set to instance of object". My team is now learning the fundamentals oops. so we do not know how to proceed!!!

    So my question is

    1) how do i make the universal method recognize the button of an invidual page (which called the method) and make it Visible/invisible ?


    One of my friend asked me to try.....

    Public Sub myGlobalSub(pge As Page, display As Boolean)
    pge.FindControl("btnAdd").Visible = display
    End Sub
    --------------------------------------------------------------------------------

    and by calling it

    VB:
    --------------------------------------------------------------------------------
    myGlobalSub(Me, True) 'Turns it on
    myGlobalSub(Me, False)'Turns it off
    --------------------------------------------------------------------------------

    But I still get error ...Object reference not set to instance of object


    Please help me -- Thank you
    Sara

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: how to reference a control in a procedure (class)

    I'm assuming you use a user control with buttons in it. To access this in your code, first find the name of your user control by looking at its properties. Let's assume your user control is named "AllMyButtons1" and it is of Type "AllMyButtons". Open your code behind and add the following variable at the class level
    VB Code:
    1. Protected AllMyButtons1 As AllMyButtons
    Now within any of your procedures you should be able to do this
    VB Code:
    1. AllMyButtons1.btnAdd.Visible=false

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: how to reference a control in a procedure (class)

    I don't think she's there yet.

    Sara: You must start by creating a web user control, and placing this web user control on every page that you want to use it on. The code for the button click events should be in the web user control's codebehind. Don't create a simple class for it, since this is a UI element you are dealing with, not a global logic procedure.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    102

    Re: how to reference a control in a procedure (class)

    Dear Friends
    Thanks for your reply and Time

    It was very helpful

    Sara

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: how to reference a control in a procedure (class)

    Now we'll never know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width