Click here to Skip to main content
Sign Up to vote bad
good
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


2 solutions

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

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 539
1 Michael Haephrati 390
2 Prasad_Kulkarni 273
3 OriginalGriff 245
4 samadhan_kshirsagar 235
0 Sergey Alexandrovich Kryukov 6,959
1 Prasad_Kulkarni 3,679
2 OriginalGriff 3,384
3 _Amy 3,332
4 CPallini 2,925


Advertise | Privacy | Mobile
Web04 | 2.6.130617.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid