views:

86

answers:

1

Hi Guys,

I have around 20 labels to update.

In relation to performance and padeload-weight, I choose WebMethods to realize it (Much smaller then updatepanel + timer).

So, how to update a lot of values in the WebMethod?

(My First intention was to access them normaly as I do: lbl1.Text = "1"; lbl2.Text = "2".... but the method is static - no chance).

+1  A: 

Create your method something like (choose some more convenient names tho :-)).

public static object MyMethod()
{
    return new {
        Value1 = "Label1Value",
        Value2 = "Label2Value",
        ...
    };
}

And do it in JavaScript like

<script type="text/javascript">
     var myObj = PageMethods.MyMethod();

     document.getElementById('<%=Label1.ID%>').innerHTML = myObj.Value1;
     document.getElementById('<%=Label2.ID%>').innerHTML = myObj.Value2;
     ...
</script>

Ah well, that'd get you started.

Jan Jongboom
Thats great, thank you. Simple question: How I can give a few parameter to the webmethod?
Kovu
by changing the method to `public static object MyMethod(string param1)`, and then call it from javascript like `PageMethods.MyMethod('paramValue');`
Jan Jongboom