[英]How to call a WebMethod from Asp.Net without using javascript
I have a bunch of [System.Web.Services.WebMethod] that I call with jquery to provide ajax functionality. 我有一堆我用jquery调用的[System.Web.Services.WebMethod]以提供Ajax功能。 Is there to call them from my codebehind files? 是否可以从我的代码隐藏文件中调用它们?
Meaning I have the following WebMethod in a file called DeleteImages.aspx.cs 含义我在名为DeleteImages.aspx.cs的文件中具有以下WebMethod
[System.Web.Services.WebMethod]
public static string deleteImage(int id, int itemID, string fileName)
{
string deleteSQL = "DELETE FROM tItemsFiles WHERE ID=@ID";
//run sql command
}
is there a way I can call this webmethod from a different codebehind file, ie CreateImage.aspx.cs 有没有一种方法可以从其他代码隐藏文件(即CreateImage.aspx.cs)调用此网络方法
Yes, you should be able to do call it directly from CreateImage
: 是的,您应该可以直接从CreateImage
调用它:
DeleteImages.deleteImage(123, 456, "image.png");
(Note that I'm not sure what your actual namespace or class names are. It's almost certain that the class name of DeleteImages.aspx.cs
will be DeleteImages
, but you may need to prefix it with a namespace when calling it, or have a using
directive at the top of your CreateImage
class.) (请注意,我不确定您的实际名称空间或类名称是什么。几乎可以确定DeleteImages.aspx.cs
的类名称将为DeleteImages
,但是您可能需要在调用它时使用名称空间作为前缀,或者使用CreateImage
类顶部的using
指令。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.