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

I make class in my web application project called Globle,
and suppose i have page called Homepage.

I want to know how to reach specific control in Homepage from Globle Class as like this:

C#
public class Globle
    {
        public static bool myMethod(Page Homepage)
        {
            Homepage.Controls.TextBox.Text = "any thing";

            return true;
        }
    }


thanks.
Posted
Updated 30-Dec-10 13:39pm
v2

1 solution

Yeah you can.

Try,

(HomePage.FindControl("YOU_CONTROL_ID") as TextBox).Text = "Any thing";


You might get NullException on runtime as because
HomePage.FindControl("YOU_CONTROL_ID")

or
HomePage.FindControl("YOU_CONTROL_ID") as TextBox

can be null. Add appropriate null exception handling get going with it.

I am not sure what type of ASP.NET project is it. You can change the access modifier of the control in Page to public and access like you said in your question if it is Web Application.
 
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