Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to access an object defined in a web-page(on page load) in a class. How can i do that..Please dont tell me to use state management.
I am using VS 2008

Regards.
Posted
Comments
[no name] 7-Oct-11 7:56am    
The very obvious solution is State management, but you're not looking for that.

Can you explain your situation in a detailed way?

What's the object, What you're trying to do, Is it local to Page_Load routine?

..So that we can think of any better alternate Solution.

1 solution

You can pass the object from your webpage into the class. For example, if you wanted to manipulate the text in a textbox using a separate class you could do something like this:

C#
public class TextBoxHelper
{
    public void TextBoxContentsToUpper(TextBox t)
    {
        t.Text = t.Text.ToUpper();
    }
}


assuming your webpage has a TextBox with ID "Name" call the class method from your webpage like this:

C#
var helper = new TextBoxHelper();
helper.TextBoxContentsToUpper(Name);
 
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