如何从vb.net中的aspx.vb页面调用webmethod [英] How to call webmethod from aspx.vb page in vb.net

查看:120
本文介绍了如何从vb.net中的aspx.vb页面调用webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是,是从aspx.vb调用WebMethod,下面是我的WebMethod语法,它位于Default.aspx.vb中

< System.Web.Services.WebMethod()> _ 
< ScriptMethod(UseHttpGet:= True,ResponseFormat:= ResponseFormat.Json)> _
公开 共享 功能 dat(_
ByVal Id 作为 整数作为列表( 项目)
Dim eve As 列表( 项目)()
eve =(从行 getItems(Id)。行
选择 使用 {
.Name = row(< span class =code-string> 名称)。ToString(),
.Description = row( 描述)。ToString(),
.ItemPic_url = row( ItemPic_url )。ToString()})。ToList()
返回 eve
结束 功能



下面是我的jquery函数,我从中调用web方法:

注意:我的Jquery函数放在我的母版页中,我从启动Default.aspx页面调用它。

  function  getItems(){
$( #tbody)空();
var id = $( select )[ 0 ]。value;
$ .ajax({
url: Default.aspx / dat
数据:{Id:id},
contentType: Application / json; charset = utf-8
responseType: json
方法: POST
成功: function (response){
$( #tbody)。 empty();
var rows = response.d;
var count = response.d.length;
var table = document .getElementById( tbody);
var 行;
var cell;
for var i = 0 ; i< rows.length; i ++){
if (i% 4 == 0 ){
row = table.insertRow();
}
cell = row.insertCell(); // 只需插入行
cell.innerHTML = < td>< ul>< li style ='text-align:center;'>< img id ='imgload'width = '190px'; height ='166px'src ='.. / Images / CatalogImgs / + rows [i] .ItemPic_url + 'alt ='未找到图像'/>< / li>< li style ='margin:4px 6px; font-weight:600; font-family:Calibri; font-size: 16px;'> + rows [i] .Name + < / li>< li style ='margin:4px 6px; color:#808080; font-weight:600;'>< p> + rows [i] .Description + < / p>< / li>< / ul>< / td>;
if document .getElementById( tbody)。rows [ 0 ]。cells.length> 0
{
// alert(文件。 getElementById(tbody)。rows [0] .cells.length);
switch (rows.length){
case 1
$( #tbody> tr> td)。css(' padding-left'' 18%');
break ;
case 2
$( #tbody> tr> td)。css(' padding-left'' 12%') ;
break ;
case 3
$( #tbody> tr> td)。css(' padding-left'' 6%') ;
break ;
默认
$( #tbody> tr> td)。css(' padding-left'' 1%');
}
}
}
},
错误:功能(xhr){
警报(xhr.status);
},
失败: function (回复){
alert(response);
}
});
}



问题:我没有输入我的网络方法。通过尝试从浏览器调试。我收到的错误如下:



未知的网络方法数据。 
参数名:systemName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender,EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)





我尝试了什么:



我尝试了以上所有代码我提到过。

解决方案

#tbody )空();
var id =


select)[ 0 ]。value;


.ajax({
url: Default.aspx / dat
data:{Id :id},
contentType: Application / json; charset = utf-8
responseType: json
method: POST
成功:功能(响应) {

What I am trying to do, Is to call WebMethod from aspx.vb, Below is my WebMethod syntax which is in Default.aspx.vb

<System.Web.Services.WebMethod()> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function dat( _
ByVal Id As Integer) As List(Of items)
    Dim eve As New List(Of items)()
    eve = (From row In getItems(Id).Rows
           Select New items With {
                                .Name = row("Name").ToString(),
                                .Description = row("Description").ToString(),
                                .ItemPic_url = row("ItemPic_url").ToString()}).ToList()
    Return eve
End Function


Below is my jquery function from which I am calling web method:
Note: My Jquery function is placed in my master page and I am calling it from startup Default.aspx page.

function getItems() {
        $("#tbody").empty();
        var id = $("select")[0].value;
        $.ajax({
            url: "Default.aspx/dat",
            data: { Id: id },
            contentType: "Application/json; charset=utf-8",
            responseType: "json",
            method: "POST",
            success: function (response) {
                $("#tbody").empty();
                var rows = response.d;
                var count = response.d.length;
                var table = document.getElementById("tbody");
                var row;
                var cell;
                for (var i = 0; i < rows.length; i++) {
                    if (i % 4 == 0) {
                        row = table.insertRow();
                    }
                    cell = row.insertCell();  //simply insert the row
                    cell.innerHTML = "<td><ul><li style='text-align:center;'><img id='imgload' width='190px'; height='166px' src='../Images/CatalogImgs/" + rows[i].ItemPic_url + "' alt='No Image Found' /></li><li style='margin:4px 6px;font-weight: 600;font-family: Calibri;font-size: 16px;'>" + rows[i].Name + "</li><li style='margin:4px 6px;color: #808080;font-weight: 600;'><p>" + rows[i].Description + "</p></li></ul></td>";
                    if (document.getElementById("tbody").rows[0].cells.length > 0)
                    {
                        //alert(document.getElementById("tbody").rows[0].cells.length);
                        switch (rows.length) {
                            case 1:
                                $("#tbody > tr > td").css('padding-left', '18%');
                                break;
                            case 2:
                                $("#tbody > tr > td").css('padding-left', '12%');
                                break;
                            case 3:
                                $("#tbody > tr > td").css('padding-left', '6%');
                                break;
                            default:
                                $("#tbody > tr > td").css('padding-left', '1%');
                        }
                    }
                }
            },
            error: function (xhr) {
                alert(xhr.status);
            },
            Failure: function (response) {
                alert(response);
            }
        });
    }


Problem: I am not entering in my web method. By trying debugging from browser. I am getting error which is mention below:

Unknown web method dat.
 Parameter name: methodName
 at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
 at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
 at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



What I have tried:

I am tried all above code which I mentioned.

解决方案

("#tbody").empty(); var id =


("select")[0].value;


.ajax({ url: "Default.aspx/dat", data: { Id: id }, contentType: "Application/json; charset=utf-8", responseType: "json", method: "POST", success: function (response) {


这篇关于如何从vb.net中的aspx.vb页面调用webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆