Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="PHP"></pre>Hello
I want to know is there anything similar to class in vb.net which can be call on all the forms just by refering its name.
similarly how can i make it in asp.net. since, asp.net some controls in a class file it shows error i.e. object reference not set to an instance of an object.
Thanks.
Posted
Comments
AmitGajjar 18-Jan-12 6:45am    
can you provide your code?

Create A class file and write your all the methods there. and on asp.net page create object of that class and use that
 
Share this answer
 
Comments
mirzamujib 18-Jan-12 5:33am    
Thanks sharma.
Will u show me a syntax to call the class from my webpage.
mirzamujib 18-Jan-12 5:58am    
I tried but it throws an error
"object reference cannot set to an instance of an object" on the line below
Dim mymenu As Menu = Master.FindControl("NavigationMenu")

Thanks
i don't really get the question but...

you can simply create a class make it public and add public method in that class and access that method from your aspx.cs code behind.
 
Share this answer
 
Comments
mirzamujib 18-Jan-12 5:37am    
Thanks Jephunneh.
Will u show me a syntax to call the class from my webpage.
Hello Mirzamujib,

pardon me for the nasty code as i am doing it real quick so here's the code to call class member from aspx page.

this is WebForm1.aspx
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <%=new WebApplication1.Class1().MyName %>
    </div>
    </form>
</body>
</html>


this is another class
C#
namespace WebApplication1
{
    public class Class1
    {
        public string MyName { get { return "naruto"; } }
    }
}



hopefully you get the idea... sorry for the code
 
Share this answer
 
v3
Comments
Jephunneh Malazarte 18-Jan-12 8:36am    
i wasn't able to include the page directives in aspx file because it throws an exception when i submit the solution here... but that's basically it :)
mirzamujib 19-Jan-12 2:06am    
Thanks Malazarte,
I'll try out the above code...
thanks again....
Jephunneh Malazarte 19-Jan-12 9:35am    
hello mirzamujib. if the solution addressed your question please click accept button :) only if it works :) thanks.

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