从appcode类调用aspx.cs方法 [英] call a method of aspx.cs from an appcode class

查看:140
本文介绍了从appcode类调用aspx.cs方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序代码为 FHAConnClass.cs 中有一个CS文件,现在我需要调用 XMLValidator.aspx.cs 文件的方法.该怎么做?

Hi,

I have a CS file in appcode FHAConnClass.cs , now i need to call a method of XMLValidator.aspx.cs file.How can i do that?

namespace FHAConnTester
{ 
    public class FHAConnClass
    {

        public string ReadTest()
       { 
//I want to call the method of aspx.cs
     requestXML ();
       }



XMLValidator.aspx.cs



XMLValidator.aspx.cs

namespace LoanScore
{
    public partial class XMLValidator : System.Web.UI.Page
    {
       public void requestXML()
        {//Do something
        }
    }
}



XMLValidator.aspx



XMLValidator.aspx

<%@ Page Language="C#"  AutoEventWireup="true" CodeFile="XMLValidator.aspx.cs" Inherits="LoanScore.XMLValidator" Title="XML Validator"   MasterPageFile="~/master/MasterPage.master"%>

推荐答案

最简单的方法是将requestXML函数移到另一个类. Page类中的方法应该是诸如Load和服务器控件事件之类的事件.不要在此处放置通用功能.那是不好的做法.
您可以通过使用静态函数来解决此问题,但这是糟糕的体系结构.
The easiest way is to move the requestXML function to another class. Methods in your Page class should be events like Load and server control events. Don''t put common functionality here. That''s bad practice.
You could solve this by using statics, but it''s bad architecture.


这篇关于从appcode类调用aspx.cs方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆