Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 9-Nov-12 3:25am
Rate this: bad
good
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
myClass.MySub()
  Permalink  
Rate this: bad
good
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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 328
1 Gihan Liyanage 292
2 Sergey Alexandrovich Kryukov 275
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web03 | 2.8.140826.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
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