Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

How to reference a class method from ASPX which is not in the Code Behind....

Hi All,

I have some code as such:

<%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" Inherits="Webtest1.WebForm1"%>
<HTML>
      <body>
            <h2>Factorial List</h2>
            <table border="2">
                  <tr>
                        Number</TH>Factorial</TH>
                  </tr>
                  <%Webtest1.MathFunctions.Factorial.CreateFactorialTable()%>
            </table>
            <form id="Form1" method="post" runat="server">
                  <P>
                        <INPUT type="text" id="Text1" name="Text1" runat="server"><INPUT type="submit" value="Submit">
                  </P>
                  <P id="P1" runat="server">
                        <asp:Button id="Button1" runat="server" Text="Button" CommandName="test"></asp:Button>
                        <asp:Button id="Button2" runat="server" Text="save"></asp:Button></P>
            </form>
      </body>
</HTML>



MathFunctions.Factorial.CreateFactorialTable() is in its own vb class file, as such.

' MathFunctions.vb
' Define a namespace
Namespace MathFunctions
    ' Define Factorial class
    Public Class Factorial
        Inherits System.Web.UI.Page

        ' Define MakeFactorial() method
        Function MakeFactorial(ByVal n As Integer) As Integeger
.......
        ' Define CreateFactorialTable() method
        Public Sub CreateFactorialTable()
........

How do I reference the CreateFactorialTable() call in the ASPX file. As you can see I have tried explicitly naming the namespace, but without success.

Thanks,

Sam

0
SamJolly
Asked:
SamJolly
  • 2
3 Solutions
 
laotzi2000Commented:
You should create a object of the class to access the method.
Or you can delcare the method to be shared.
0
 
nauman_ahmedCommented:
If this function has been defined in the same namespace as of project then you can call it anytime you want. Instead of

Webtest1.MathFunctions.Factorial.CreateFactorialTable()

use

MathFunctions.Factorial.CreateFactorialTable()

HTH, Nauman.
0
 
samtran0331Commented:
Try adding the import to the top of the code-behind for webform1.

Imports MathFunctions.Factorial

In your class, make it a a public shared function

 Public Shared Function MakeFactorial(ByVal n As Integer) As Integer
   ....
 End Function
0
 
samtran0331Commented:
Also, check your html of your table....
          <table border="2">
               <tr>
                    Number</TH>Factorial</TH>
               </tr>
               <%Webtest1.MathFunctions.Factorial.CreateFactorialTable()%>
          </table>


I see 2 closing </TH> tags and no opening ones.
CreateFactorial is a sub and won't return anything to write.
Plus putting that call at </tr> xxxxxxx </table>
I don't think you will get anything on the screen....

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now