如何在另一个网页的一个网页中调用方法 [英] how to call a method in one web page in another web page

查看:242
本文介绍了如何在另一个网页的一个网页中调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我知道我在问一个基本问题,请原谅我。



我有一个方法,例如在一个网页中说FirstCode()在一个具有一些功能的解决方案中。



我在同一个解决方案中有另一个网页并且我在这个页面中使用了相同的方法FirstCode()而没有在第二个网页中再次重写代码,只需要调用该方法。



i知道它是基本的oops概念,但是因此需要学习

Hi,

I know i am asking a basic question,please excuse me for that.

I am having a method for example say "FirstCode()" in a webpage ina solution with some functionality.

I am having another web page in the same solution and i nned to use the same method "FirstCode()" in this page without rewriting the code again in second web page,just i need to call the method.

i know it is basic oops concept,but nned to learn hence asking

推荐答案

你可以这样试试

假设你有一个这样的页面 WebPage1.aspx.cs 它包含一些方法



you can try like this
suppose you have a page like this WebPage1.aspx.cs it contains some method as

 public string SomeMethod() 
 { 
return "something";
}



您可以通过创建类的实例并访问成员来访问任何页面中的此方法


you can access this method in any page by creating an instance of the class and access the members as

WebPage1 obj = new WebPage1();
 var some = obj.SomeMethod();





你也可以通过另一种方法做同样的方法,使方法为 static



注意确保该方法对页面控件没有依赖性


检查出来:如何将一个Web表单的函数或方法调用到其他Web形式使用asp.net [ ^ ]


这篇关于如何在另一个网页的一个网页中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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