Click here to Skip to main content
15,885,693 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can I create class object in aspx page load Event??
Suppose I have Page Test.aspx

Test.aspx Page

C#
< %@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" ... %>
<style language="c#"  runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        ClassTest Cls = new ClassTest();
        
    }
</style>

I am beginner, so please help me.
thank u.
Posted
Updated 6-Dec-13 2:05am
v2

Yes, you can.
In your example, the code will work fine, but the class instance will be destroyed when the event handler exits, but yes, you can create it.
 
Share this answer
 
Comments
GANESHGITE 6-Dec-13 22:38pm    
thank you for giving me feedback.. Can you tell me how can I create an object in .aspx page??
Please provide example so I can implement it.
GANESHGITE 7-Dec-13 0:14am    
I got solution...
As mentioned by OG, yes you can. However, web programming is very different than windows programming so if you are expecting the instance of that class to be available during postbacks, it won't be unless you instantiate it every time the page loads.
 
Share this answer
 

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