1

I am trying to call a method in my server-side vb code from jquery.

    import System.Web.Services
    ...
    'my VB.net Code
    <WebMethod()> _
    Public Shared Function SubmitReport_Click()
        'this is where my code will go
        Return Nothing
    End Function

In my javascript code the alert is being called but the SubmitReport_Click is not being called.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>

<script type="text/javascript">
    $("#<%= FileInput.ClientID%>").on('filebatchselected', function (event) {
        alert("file input");
        pagemethods.SubmitReport_Click();
    })
</script>
5
  • I am pretty sure that isn't possible but maybe someone smarter than me will chime in. Commented Jul 16, 2015 at 20:27
  • I am not getting any errors and the alert("file input") is being called on this particular event Commented Jul 16, 2015 at 20:31
  • I don't know will this help <WebMethod(EnableSession:=True)> this I use, but for Public Shared Sub ... and every time work. btw. is this important PageMethods... ? upper/lower case Commented Jul 16, 2015 at 20:59
  • btw. what is Your code under that function? Commented Jul 16, 2015 at 21:11
  • Currently i just am just assigning a variable with a breakpoint to make sure it is being called Commented Jul 17, 2015 at 12:13

2 Answers 2

2

I'd make a function that fires on the click event and calls over to your web method using AJAX, and use JSON to pass any relevant data.

$(".clickMe").click(doWebMethod);

function doWebMethod () {    
    var data = { 'name': 'jessikwa' , 'location': 'ny' }
    var params = "{'dataPackage': '" + JSON.stringify(data) + "'}";
    $.ajax({
        type: "POST",
        url: webMethodUrl,
        async: true,
        data: params,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert(msg.d);
        },
        error: function () {
            alert("fail");
        }
    });
}

//VB HERE

<WebMethod()> _
Public Shared Function SubmitReport_Click(ByVal dataPackage as String) as String
    Dim rtnStr As String = "OK"
    //deserialize data package here
    Return rtnStr
End Function
Sign up to request clarification or add additional context in comments.

1 Comment

Updated answer to clarify passing data
0

You can use an Ajax request. I just typed this up, so you may need to Google the syntax in case I messed it up.

$.ajax({
    type: "GET",
    url: "FileName.aspx/SubmitReport_Click",
    success: function(){
        alert('It Worked!');
    },
    failure: function() {
        alert('It Failed!');
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.