如何从一个页面在asp.net使用C#调用函数到另一个页面 [英] How to call function from one page to another page in asp.net using c#

查看:190
本文介绍了如何从一个页面在asp.net使用C#调用函数到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的.NET和Web开发了。我有网站用C#。我要声明一个类,并在该类我要声明一个函数和函数希望在第二页上打电话。因此,如何写code是什么?

I am new to .NET and Web development too. I have website written in c#. I want to declare one class and in that class i want to declare one function and that function want to call on second page. So how to write code for that?

说我有2页。一是reference.aspx和第二页是edituerprofile.aspx。在reference.aspx页我想写类,并在该类想编写一个函数。而且功能要在edituserprofile.aspx打电话。

Say I have 2 pages. One is reference.aspx and second page is edituerprofile.aspx. In reference.aspx page i want to write class and in that class want to write one function. And that function want to call in edituserprofile.aspx.

该怎么写?
请帮助我。
感谢名单提前

How to write this? pls help me. Thanx in advance

推荐答案

请按照下面的步骤

1)添加新的类文件,它是由Visual Studio中创建自己的APP_ code文件夹

1)add new class file to your app_code folder which is created by visual studio itself

2)写的,什么是你所需要的,在该类文件写入

2)write, what are all the methods/functions you need, write on that class file

3)建立在你的asp.net页面的对象该类

3)create an object in your asp.net page for that class

4)使用的object.method /函数名()调用类的梅索德/功能;

4)call the methode/function of class by using object.method/function_name();

这就是它

简单code的朋友......

Simple code friend...

string user_name="Some_user",password="correct_password";

login(user_name,password)
{
 class_name object=new class_name();
 if(true==object.methode_name(user_name,password))
           //        do_something
 else
           //        do_something
}

在你的类文件

 class class_name
 {
    public bool methode_name(string user_name,string password)
    {
        //your code here 
        if(/*yout code here to validate user*/)
            return true;
        else
            return false;

    }
}

这篇关于如何从一个页面在asp.net使用C#调用函数到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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