Make sure the class isn't marked private (by default it is, so add the word 'public' to the class declaration; i.e public class Class1).
If that doesn't work, then this might be a quick of Visual Studio; in your default page (the code behind), type
Class1 c = new Class1();
This will probably have the req lines underneath, but if you hover over the type name (Class1), you should get an option to 'generate a class for Class1'. Select this and the class will be created in the root folder. then, simply drag the Class1.cs file
into your desired folder.
Like I said, this is just a quirk of visual studio- you should just be able to create a class in your folder and then, providing the class isn't private, access it using the code above.
vahid bakkhi
Member
341 Points
304 Posts
how to create instance of a class outside App_code
May 28, 2012 03:03 PM|LINK
hi
i create a folder called Class and create a class into it called Class1
now i how to create a instance of the class in default page
please help me how to it do
thanks
donpisci
Member
74 Points
178 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 03:14 PM|LINK
Is it in the same namespace?
vahid bakkhi
Member
341 Points
304 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 03:29 PM|LINK
thanks for your answer
i create a namespace called myClass
donpisci
Member
74 Points
178 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 03:37 PM|LINK
No worries- did it help?
vahid bakkhi
Member
341 Points
304 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 03:39 PM|LINK
when i want using namespace Unknown
donpisci
Member
74 Points
178 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 03:53 PM|LINK
Make sure the class isn't marked private (by default it is, so add the word 'public' to the class declaration; i.e public class Class1).
If that doesn't work, then this might be a quick of Visual Studio; in your default page (the code behind), type
This will probably have the req lines underneath, but if you hover over the type name (Class1), you should get an option to 'generate a class for Class1'. Select this and the class will be created in the root folder. then, simply drag the Class1.cs file into your desired folder.
Like I said, this is just a quirk of visual studio- you should just be able to create a class in your folder and then, providing the class isn't private, access it using the code above.
vahid bakkhi
Member
341 Points
304 Posts
Re: how to create instance of a class outside App_code
May 28, 2012 04:03 PM|LINK
thanks
i check it ,it's public
and i try drag on page :
http://localhost:46497/myCMS/Class/Class2.cs
and i when write Class2 obj=new Class2();
but vs generate it in App_code folder
but i want create in my folder