Click here to Skip to main content
12,758,462 members (31,638 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
I am working
I have connected the web app to database.
i want to use now navigator buttons to go through the rows of the table.
it is supposed that when i double click a button in default.aspx.. should bring up a private sub in default.aspx.vb
BUT it doesnt work!! When I double click the button it leads to a function button1_onclick
hoow can i call the private sub from this function???
I have tried call mysub()
where mysub is the name of the private sub but it doesnt work
Posted 9-Nov-12 4:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If your private function is not in the same class as your click event handler, you can't do it... that is because private functions are private to their class. So let's say you have the following:

Module MainFunctions
  Private Sub MySub()
    ' do something here
  End Sub
End Module

And from within default.aspx you try call MySub() it will not work because MySub is declared as private and you are making the call from within the default.aspx class. (There is a class behind that page... that is the code-behind where you are finding the button1_Click event handler.)

If you want to be able to call MySub from within the event handler, MySub either needs to be Public or Friend. (I suggest Friend) This is true for functions and subs in either a module (which is a static class in VB) or a regular class. Of course, for a class you have to create an instance of the class before you can call the method:

Dim myClass as new MyClass
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you are calling a method from your aspx to code behind, the method called should have the protected access modifier instead of private

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100