admin管理员组文章数量:1402041
I am trying to call a method in my server-side vb code from jquery.
import System.Web.Services
...
'my VB 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>
I am trying to call a method in my server-side vb code from jquery.
import System.Web.Services
...
'my VB 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>
Share
Improve this question
asked Jul 16, 2015 at 20:24
Jake HunterJake Hunter
1411 gold badge2 silver badges8 bronze badges
5
- I am pretty sure that isn't possible but maybe someone smarter than me will chime in. – Gary Storey 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 – Jake Hunter Commented Jul 16, 2015 at 20:31
-
I don't know will this help
<WebMethod(EnableSession:=True)>
this I use, but forPublic Shared Sub ...
and every time work. btw. is this importantPageMethods...
? upper/lower case – nelek Commented Jul 16, 2015 at 20:59 - btw. what is Your code under that function? – nelek 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 – Jake Hunter Commented Jul 17, 2015 at 12:13
2 Answers
Reset to default 2I'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
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!');
}
});
本文标签: javascriptHow do I call a server side VBnet function from jquery in an aspnet formStack Overflow
版权声明:本文标题:javascript - How do I call a server side VB.net function from jquery in an asp.net form? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744345558a2601735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论