Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

trying to get td contols in a webmethod.

$
0
0

Hi.

I have this code:

$(document).ready(function () {
            var city = {};
            city.Name = 'Athens';
            city.Population = mytd;
            $.ajax({
                type: 'POST',
                url: 'Default.aspx/GetCity',
                data: "{city:" + JSON.stringify(city) + "}",
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (r) {
                    $.each(r, function (index, i) {
                        alert(i.Name);
                    });
                },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });
        });

and vb code:

<WebMethod()> _<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Shared Function GetCity(ByVal city As City) As String
        Dim js As JavaScriptSerializer = New JavaScriptSerializer()
        Dim c As Object = city
        Dim strJSON As String = js.Serialize(city)

        
    End Function

Public Class City
    Private _name As String
    Public Property Name As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    Private _population As HtmlTableCell
    Public Property Population As HtmlTableCell
        Get
            Return _population
        End Get
        Set(ByVal value As HtmlTableCell)
            _population = value
        End Set
    End Property
End Class

i have this markup:

<table><tr><td runat="server" id="mytd"><input id="Button1" type="button" value="button" /></td></tr></table>

When the Jquery goes into the webmethod i am examining the city.population, expecting to see the button1 but in the controls i see count=0. Is there a way to get the td in the webmethod?

If i do a page load (td runat on server) i can see on the contols.count =1 that is the correct.

Is there a problem because webmethod is declared as shared? If so, what can i do to get the htmltablecell value? also i can't use fincontrol inside the shared method. I cannot see the declaration.

Thanks.




Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>