Could some please help: I have a asp.net application where I call a [WebMethod] from the forms "OnUnload" method. The problem I'm having is in the WebMethod I need to either pass an arguement into the functon or access a hidden field value. The problem I'm having is that 1. the WebMethod will not fire if it has an argument in it. 2. The web method has to be static to work and because of being static I get this error when trying to access the hidden fields value "An object reference is required for the non-static field, method, or property".
Would anyone have any idea how to do this?
Thanks
Dave.
Here is my code
<head runat="server">
<title>Image Viewer</title>
<script language="javascript" type="text/javascript">
function cleanup() {
//var path = document.getElementById('<%= delPath.ClientID %>').value;
PageMethods.DeleteFile();
}
</script>
</head>
<body onunload="cleanup()">
<form id="imgDisplay" runat="server">
<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
</asp:ScriptManager>
<div style="width: 700px; height: 800;">
<asp:Image ID="Image" runat="server" with="100%" Height="100%" />
</div>
<asp:HiddenField ID="delPath" runat="server" />
</form>
</body>
</html>
Here is the page function
Note: I use "using System.Web.Services;"
[WebMethod]
public static void DeleteFile()
{
string path = delPath.Value;
//string del = "~/ImgResize/" + Path.GetFileName(path);
//System.IO.File.Delete(HttpContext.Current.Server.MapPath(del));
}