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

Posted on 2005-05-12
Last Modified: 2010-04-07
Hi All,

I have some code as such:

<%@ Page Language="vb" Codebehind="WebForm1.aspx.vb" Inherits="Webtest1.WebForm1"%>
            <h2>Factorial List</h2>
            <table border="2">
            <form id="Form1" method="post" runat="server">
                        <INPUT type="text" id="Text1" name="Text1" runat="server"><INPUT type="submit" value="Submit">
                  <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>

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.



Question by:SamJolly
    LVL 12

    Assisted Solution

    You should create a object of the class to access the method.
    Or you can delcare the method to be shared.
    LVL 25

    Accepted Solution

    If this function has been defined in the same namespace as of project then you can call it anytime you want. Instead of




    HTH, Nauman.
    LVL 37

    Assisted Solution

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

    Expert Comment

    Also, check your html of your table....
              <table border="2">

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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now