如何将Web方法值传递给标签 [英] How to Pass web Method Value to a Label

查看:73
本文介绍了如何将Web方法值传递给标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述









我有一个用于创建图表的网页方法chart.js ...我想将一个字符串值传递给一个标签......我将给出web方法的详细代码...







Hi,



I have a web method that is used to creat a a chart using chart.js... I want to pass a string value to a label... I will give the detailed code for the web method...



<WebMethod()> _
        Public Shared Function GetZoneData(ByVal strMode As String) As String()
        Return GetZoneSalesData(strMode)
    End Function

    Private Shared Function GetZoneSalesData(ByVal strMode As String) As String()
        Dim clsSales As New TS.Corporate.SalesGenerateBarChart
        Dim dTable As New DataTable
        dTable = clsSales.ZoneSalesValue(strMode)
        Dim resultdata = From d In dTable.AsEnumerable()
        Dim data(dTable.Rows.Count - 1) As String
        For i As Integer = 0 To dTable.Rows.Count - 1
            Dim item As DataRow = dTable.Rows(i)
            data(i) = (String.Format("{0}-{1}", item("zone"), item("zoneTotal")))
        Next

        Return data
    End Function









我想添加另一组值被传递到客户端......



它将如下











I want to add another set of values to be passed on to the client side...

It will be as follows



Dim clsSales As New TS.Corporate.SalesGenerateBarChart
        Dim strHead As String = clsSales.ZoneSalesString(strMode)





这是生成图表的标题,其值为从strMode参数生成。我想传递strHead值并将其显示在标签上...如何使用Ajax将此值传递给标签...







问候,



Sajin



This is a Heading for the chart generated and the value is generated from the "strMode" parameter. I want to pass that strHead value and display it on a label... How can I pass this value to a label using Ajax...



Regards,

Sajin

推荐答案

当你知道我们无法访问web方法中的控件,所以你需要使用JavaScript / Jqury来设置标签值。

//首先你需要调用javascript然后从它调用web方法,见下面的代码片段



As you know we can not access controls in web method, so You need to use JavaScript/Jqury to set label value.
//first you need to call javascript and then call web method from it, see below snippet

//IN ASPX
//from javascript call webmethod and pass parameters if exist and give call method
function callwebmthod()
{
PageName.MathodName(Param1, Param2, MathodName_CallBack);
}


function MathodName_CallBack(response) 
{
   //here response object contains return result
   var szReturnFromWebmethod = response.value;
   //store return value in label
   document.getElementById("label1").innerHTML = szReturnFromWebmethod;

}







//in .CS page define webmethod
[Ajax.AjaxMethod()]
public string MathodName(string Param1, string Param2)
{
    //your method code goes here
}







'value'属性无法设置值到标签,你需要使用'innerHTML'属性,见下面的代码片段




'value' property is not able to set value to label, you nee to use 'innerHTML' property, see below snippet

//for IE
 document.getElementById("label1").innerHTML = "change in text or whatever";

//other than IE
 document.all("label1").innerHTML ="change in text or whatever"


这篇关于如何将Web方法值传递给标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆