使用处理程序中下拉列表中的值

时间:2014-04-06 15:14:15

标签: javascript jquery asp.net vb.net

如果有人可以节省一些时间,我真的可以使用一些帮助。我试图从我的内容页面访问母版页上的下拉列表(dropdownlist1)的值,然后在.ashx代码页中的hanlder中使用该变量。为了测试它,我试图在消息框中显示变量。任何想法都将不胜感激。

内容页面(下拉列表位于母版页上)

$(document).ready(function $("#DropDownList1").change(function () {
            location.reload;


            alert($(this).val());
            strTrail = $(this).val();
            alert(strTrail);

        });

处理程序

Case "SearchByLocation"
            Dim firstTime As Integer = 0
            Dim latitude As String = "42.9901009" 'context.Request("Latitude")
            Dim longitude As String = "-81.146698" 'context.Request("Longitude")
            'Dim fromdate As String = context.Request("#DropDownList1").val


            Dim strTrail As String = context.Request("#DropDownList1")
            MsgBox("now")
            MsgBox(strTrail)
            'strTrail = context.Request("strTrail")
            If firstTime < 1 Then
                strTrail = "Lookout"
            End If


            Dim objCBL As New JParkinsonLookUP.JPLookUp

            Dim objDS As System.Data.DataSet = objCBL.SearchByTrail(strTrail, latitude, longitude, 10)

            'result = "{""Locations"":[{""ID"":""1"",""Latitude"":""28.537"",""Longitude"":""-81.380""}]}"

            result = "{""Locations"":["
            For Each dr As System.Data.DataRow In objDS.Tables(0).Rows

                result += "{""ID"":""" & dr("ID").ToString() & """,""Latitude"":""" & dr("Latitude").ToString() & """,""Longitude"":""" & dr("Longitude").ToString() & """},"
            Next

            result = result.Substring(0, result.LastIndexOf(","))

            result += "]}"
            firstTime = 1


        Case "SearchByDescription"


    End Select


    'second command
    'third command

    context.Response.Write(result)



End Sub

1 个答案:

答案 0 :(得分:0)

所有这一切都避免 msgbox 因为它会抛出异常(在aspnet页面竞赛中无效)

第二个,当你要浏览document.ready时,你必须根据你的代码发出ajax请求,你将返回json对象,然后你需要在javascript中解析对象的广告读取值。

   $.ajax(
{
type: "GET", url: url, data: qry,
success: function (msg) {
    lat = msg.Locations[0].Latitude;
    lng = msg.Locations[0].Longitude;
   alert(lat +' ' + lat);
},
error: function (msg) {
    $("#coor").html("errore durante l'elaborazione");
}
});

另一个重要的事情是使用此指令来设置您的回复:

        context.Response.ContentType = "application/json";

请务必通过Chrome或Firefox查看您的回复并通过网络电话致电,以便您获得更多信息。 这是代码不是测试我在我的最后使用一些工作代码并进行一些更改,让你有一个想法。

相关问题