开发者

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. Is there to call them from my codebehind files?

Meaning I have the following Web开发者_如何学运维Method in a file called DeleteImages.aspx.cs

 [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


Yes, you should be able to do call it directly from 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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜