如何使用静态方法设置标签文本 [英] How to set label text using static method
本文介绍了如何使用静态方法设置标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[System.Web.Services.WebMethod]
public static string GetCurrentTime( string name)
{
output.InnerText =姓名;
string nam2e = System.Web.HttpContext.Current.Request.QueryString [ CODE跨度>]; ;
return Base64代码: + name + nam2e;
}
< label id = 输出 runat = 服务器 > ; < / label >
任何想法如何通过静态方法设置标签文本?
我尝试了什么:
即时通讯使用静态方法,因为我使用javascript函数调用c#方法
解决方案
您好
您可以在静态方法中定义名称并将其传递给JavaScript函数:
[HttpPost]
public string LableName( string 名称)
{
返回名称;
}
和JS:
public Lable(response)
{
document .getElementById( YourLableID)。innerHTML = response;
}
无法在Web方法中更新ASP控件。
,因为您传递了值从ajax和更新标签没有任何逻辑,你应该更新客户端本身的标签
文件 .getElementById( LabelID)。innerHTML = ' 某些值';
或者如果要执行某些逻辑,则返回值在web方法中并在ajax调用的成功方法中更新相同的方法。
注意:在静态方法中不能使用非静态成员。
[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;
}
<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
解决方案
Hello
you can define the name in your static method and pass it to JavaScript function:
[HttpPost] public string LableName(string Name) { return Name; }
and in JS:
public Lable(response) { document.getElementById("YourLableID").innerHTML = response; }
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
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.
这篇关于如何使用静态方法设置标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文