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
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:
Protected AllMyButtons1 As AllMyButtons
Now within any of your procedures you should be able to do this
VB Code:
AllMyButtons1.btnAdd.Visible=false
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.
Re: how to reference a control in a procedure (class)
Dear Friends
Thanks for your reply and Time
It was very helpful
Sara
Re: how to reference a control in a procedure (class)