Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
    output.InnerText = name;
    string nam2e = System.Web.HttpContext.Current.Request.QueryString["CODE"]; ;
    return "Base64 code :" + name + nam2e;
}


ASP.NET
<label id="output" runat="server"></label>


any idea how to set the label text thru static method?

What I have tried:

im using static method because i use a javascript function call the c# method
Posted
Updated 14-Nov-16 19:09pm

Hello
you can define the name in your static method and pass it to JavaScript function:

C#
[HttpPost]
public string LableName(string Name)
{
   return Name;
}


and in JS:
JavaScript
public Lable(response)
{
  document.getElementById("YourLableID").innerHTML = response;
}
 
Share this answer
 
Its not possible to update the ASP controls in a web method.
since you are passing the value from ajax and updating the label without any logic, you shall update the label in the client side itself
JavaScript
document.getElementById("LabelID").innerHTML = 'Some Value';

or if you want to perfrom some logic, then return the value in web method and update the same in success method of ajax call.

Note:Its not possible to use Non static members inside a Static method.
 
Share this answer
 

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