Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<script type="text/javascript">
       function ShowCurrentTime() {
           var base64 = $('#colors_sketch')[0].toDataURL();
           $.ajax({

               type: "POST",
               url: "Dms_BOM.aspx/GetCurrentTime",
               data: '{name: "' + base64 + '" }',
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: OnSuccess,
               failure: function (response) {
                   alert(response.d);
               }
           });
       }
       function OnSuccess(response) {
           alert(response.d);
       }
   </script>


C#
[System.Web.Services.WebMethod]
   public static  string GetCurrentTime(string name)
   {
       FILLHOD(name);
       return "Base64 code :" + name ;
   }

C#
protected void FILLHOD(string name)
  {


  }


i use ajax function pass data to code behind,from static method call a non static function for insert data to database but getting some error :An object reference is required for the nonstatic field, method,any ideas how to deal with this issue,and is that possible connect ajax function to non static function in c#?

What I have tried:

Nothing.
Posted
Updated 13-Nov-16 21:50pm
v2
Comments
Karthik_Mahalingam 15-Nov-16 0:49am    
not possible

1 solution

Make FILLHOD static as well.

C#
protected static void FILLHOD(string name)
 
Share this answer
 
Comments
KyLim0211 14-Nov-16 3:58am    
no,i want use that function to get user employeeID and company id
F-ES Sitecore 14-Nov-16 4:08am    
Why does it being static stop you? One thing you have to appreciate is that a web method is an isolated function, you're not in the middle of a postback so you can't access any server-controls, the view state and so on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900