Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working vb.net
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

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:

VB
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:

VB
Dim myClass as new MyClass
myClass.MySub()
 
Share this answer
 
If you are calling a method from your aspx to code behind, the method called should have the protected access modifier instead of private
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900