Martin
Martin

Reputation: 49

Jquery ajax function to call code behind in vb file

First of all, what i am trying to do is to populate a drop down box like this:

<asp:DropDownList CssClass="ui dropdown" ID="drpGolfClub" runat="server"></asp:DropDownList>

With some values giving me golf club id and names. The problem is that with jQuery i cant seem to run the code in the vb file behind. it all looks like this. In the aspx file:

 function loadGolfClub()
        {
                alert('inside method');
                //debugger;
                $.ajax({
                    type: "POST",
                    url: "Register.aspx/LoadGolfClub",
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: false,
                    success: function (Result) {

                        debugger;
                        Result = Result.d;
                        $('#<%=drpGolfClub.ClientID%>').empty();
                        $('#<%=drpGolfClub.ClientID%>').prepend("<option value='0'>" +"Select" + "</option>");
                        $.each(Result, function (key, value) {
                            $('#<%=drpGolfClub.ClientID%>').append($("<option></option>").val(value.GolfClubId).html(value.GolfClubName));
                            $('#<%=drpGolfClub.ClientID%>')[0].selectedIndex = 1;
                        });
                        alert("in sucess!");
                    },

                    failure: function () {
                        alert("Failed!");
                    }
                });
            } 

The aspx file's vb behind is added like this:

Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Owin
Imports System.Data
Imports System.Web.Services
Imports System.Reflection
Imports Golfbook.CoreLibrary
Imports Golfbook.CoreLibrary.Golfbook.Services


Public Class Register
    Inherits System.Web.UI.Page
    Shared objGCBO As New GolfClubBO()

    Shared objGolfClubService As New Golfbook.CoreLibrary.Golfbook.Services.GolfClub.GolfClubDetails

    Shared details As New List(Of GolfClubBO)()
    Shared _loginName As String
    Shared loginName As String

    Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub

    <WebMethod()>
        <System.Web.Script.Services.ScriptMethod(ResponseFormat:=System.Web.Script.Services.ResponseFormat.Json)>
        Public Shared Function LoadGolfClub() As GolfClubBO()
            Dim details As New List(Of GolfClubBO)()
            Try
                details = objGolfClubService.LoadGolfClub()
            Catch ex As Exception

            End Try
            Return details.ToList.ToArray()
        End Function
End Class

I know that page_load in vb is run, but it never goes to the function there. I have tried "everything" now, and have no idea what to do. the alert boxes added in the function is trigging, so it do begin to run

I know the JQuery is working cause i have added som values into a random textbox: $('#txtFirstName').val('Martin');

Any tips on what can be the reason of this?

Upvotes: 0

Views: 1652

Answers (1)

Martin
Martin

Reputation: 49

As written above, thanks to ADyson, the answer to my trouble was fixing this: Inside ~/App_Start/RouteConfig.cs change:

settings.AutoRedirectMode = RedirectMode.Permanent;
To:

settings.AutoRedirectMode = RedirectMode.Off;

Thank you all for the response!

Upvotes: 2

Related Questions