简体   繁体   English

如何在C#(ASP.NET 2.0)中将值从一个类返回到另一个

[英]How to return a value from one class to another in C# (ASP.NET 2.0)

I have a class with code (simplified): 我有一个带有代码的类(简体):

namespace CustomerData
{
    public class InsertCustomer
    {
    public string name { get; set; }
        public string customerID { get; set; }

    public string Add()
    {
        //Insert into a database

        //Condition to check if the insert was successfull
        if (successful)
        {
            return id;
        }
        else
        {
            //If the insert was not successfull
        }
    }


    }
}

Now I want to pass this value to my web service (ASP.NET 2.0) in the same solution as the class above (simplified code): 现在,我想以与上述类相同的解决方案(简化代码)将此值传递给我的Web服务(ASP.NET 2.0):

namespace CustomerData
{
    [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService] 

    [WebMethod]
        public string deleteCustomer(string customerID)
        {
            return customerID;
        }

And essentially I then want to have an AJAX GET function that gets this ID and execute a function with this variable but if I can get the value to my WebMethod I think I'll be good from there. 然后本质上,我想要一个AJAX GET函数来获取此ID并使用此变量执行一个函数,但是如果我可以将值获取到WebMethod中,那么我认为我会从中受益的。

Any suggestions on how to do what topic describes? 关于如何执行主题描述的任何建议? Thanks in advance. 提前致谢。

Have you considered calling your web method from your InsertCustomer class? 您是否考虑过从InsertCustomer类调用Web方法?

    CustomWebService srv  = new CustomWebService;
    srv.deleteCustomer(returnedCustomerID);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在asp.net C#中从一帧传递值并在另一帧接收? - How to pass a value from one frame and receive in another frame in asp.net C#? 如何在asp.net c#中将GridView的值从一个页面传递到另一个页面? - How to pass value of GridView from one page to another in asp.net c#? 如何通过asp.net C#中的查询字符串在网格视图中将数据从一个类获取到另一类 - How to get data from one class to another class in grid view through query string in asp.net C# 从一个类文件访问标签到另一类文件c#和asp.net - Access a Label from one class file to another class file c# and asp.net 如何使用asp.net C#将一个标签值传输到另一个标签以显示视频名称 - How to transfer one label value to another label for displaying video Name using asp.net C# 如何使用 ZD7EFA19FBE7D3972FD745ADB602422 方法从 ASP.Net Javascript AJAX 请求返回 boolean 值? - How to return boolean value from ASP.Net Javascript AJAX request with C# Method? 如何将SQL结果从一页传递到另一C#asp.net - How to pass SQL results from one page to another C# asp.net 如何将C#更改从一个ASP.NET应用程序转移到另一个? - How to transfer C# changes from one ASP.NET application to another? 在C#ASP.NET,MVC中,如何从INSIDE输出任意文本? - How does one output arbitrary text from INSIDE a control class in C# ASP.NET, MVC? 如何使用 Linq 从 C# ASP.NET MVC 4 中的 IQueryable 中找到一个值? - How to find one value from an IQueryable in C# ASP.NET MVC 4 using Linq?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM