You must Sign In to post a response.
  • Category: ASP.NET

    How to call a method in aspx.cs from Class file?

    How to call a method in aspx.cs from Class file?

    Class.cs
    public int progressbar(int Total)
    {
    // all validation are done here. Based on each validaiton done Im displaying a progress bar message accordingly..
    System.Web.UI.Page.UpdateProgress(msg,total); // How to call this file??????

    }


    aspx.cs

    public static void UpdateProgress(string msg, int percent)
    {

    System.Web.HttpContext.Current.Response.Write(String.Format("<script type=\"text/javascript\">parent.UpdateProgress({0}, '{1}');</script>", percent, msg));

    System.Web.HttpContext.Current.Response.Flush();
    }
  • #765683
    hi

    easy way put method in your class then call from aspx becos controls value we can get only aspx page so

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #765684
    I hope you understand the OOP concept. you have the method"progressbar" in Class.cs correct. And also its a non static method correct.

    So if you want to call this method from other classes, you have to create instance and call the method
    If you want to call in the same class you can call directly. According to your requirement you can change the access modifier(public, private, internal etc.. ) and access the method.

    By Nathan
    Direction is important than speed

  • #765685
    Hi Lily,

    If I understood your question correctly,you want to call UpdateProgress method from class.cs file which is a static method.
    In that case you can call the method by classname.methodname like classname.UpdateProgress() method.

    Hope it helps!

  • #765713
    HI,
    It seems you want to access presentation/GUI layer details from business layer.
    For this you need to create 2 seperate solutions viz 1 for WebPages and 2nd for DataClasses.
    Build a WebPages solution and add its lirary as a reference to DataClasses solution. Then you can easily create objects of required pages inside classes and call required functions.

  • #765736
    Hi
    try this code

    public class Class1
    {
    public void dd()
    {
    Employee dd = new Employee();
    dd.InserEmployee();
    }
    }

    Employee is aspx class name

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments