Search code examples
c#asp.net.netupdatepanel

How to access controls from aspx file in other .cs files


I have a aspx file where controls are written. I want to access these controls in .cs file which is not code of this aspx file but another class file.

For example: I want to update an UpdatePanel from another .cs file.

How can I do this?


Solution

  • Just pass it as a parameter to the method in the other class file. Something like:

    public class OtherClassFile
    {
        public static void UpdateMethod(UpdatePanel panel)
        {
            //Update the panel here
        }
    }
    

    Then the methdod call in your .aspx page would look like this:

    OtherClassFile.UpdateMethod(MyUpdatePanel);