Link to home
Start Free TrialLog in
Avatar of Sandeep Sood
Sandeep SoodFlag for India

asked on

public functions/procedures/variables in asp.net (vb.net)

Hello.
Kindly guide me.
in my asp.net project, where i can place my public functions/procedures/variables that can be called from any other page/form
Without using a class.
i am using vb.net.
Avatar of HainKurt
HainKurt
Flag of Canada image

create a class file
put all your proc/functions here

if you dont need to initialize the class, then use "public shared" for others use "public/private"
or create a base page that inherits from system.web.ui.page
add all procedures/functions here
then inherit all your pages from this base instead of system.web.ui.page

or add your procedures / functions to master page if you already use master page...
Avatar of Sandeep Sood

ASKER

>> or create a base page that inherits from system.web.ui.page
add all procedures/functions here
then inherit all your pages from this base instead of system.web.ui.page

Can you please give me an example/code.
Public Class MyBasePage
    Inherits System.Web.UI.Page

    const clientid as integer = 101
    const lang as string ="EN"

    Private Sub Page_Load(ByVal sender As System.Object, _
             ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private function cube (n as integer) returns integer as
    begin
        return n*n*n
    end
End Class

Open in new window


then all other pages will inherit from MyBasePage not System.Web.UI.Page

Public Class Form1
    Inherits MyBasePage

End Class

Open in new window


and here you should be able to use constants / functions and procedures as if they are in current page/form

but all of these solutions uses class!
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot Experts !