如何在Web用户控件中使用Ajax发布方法 [英] how to use ajax post method in web user control

查看:120
本文介绍了如何在Web用户控件中使用Ajax发布方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

页面名称:test.ascx

hi all,

page name :test.ascx

$.ajax({
            type: 'POST',
            url: 'test.ascx/GetRandomSalt',
            contentType: 'application/json; charset=utf-8',
            data: {},
            dataType: 'json',
            async: false,
            success: function (r) {
                result= r.d;
                document.getElementById('<%=hdnRandomKey.ClientID %>').value = result;
                callback(result);
            }, error: function (x, e) {
                alertify.alert("Server not responding, Please try again later.")
            }
        });



在这里,我已经在另一个文件夹中的三个不同的aspx页面中使用了这个test.ascx用户控件.

在ADMIN文件夹中
----------------
first.aspx
second.aspx
third.aspx

这三个具有test.ascx的aspx页面

在USERCONTROL文件夹中
----------------------
test.ascx

ADMIN文件夹和USERCONTROL文件夹都在同一路径中


问题是如果我将webmethod放置在first.aspx.vb中,它的工作是否正常(这意味着我必须在三页中编写相同的代码).取而代之的是,我将webmethod放在了test.ascx.vb文件中,这意味着它无法正常工作.

要求是我需要在test.ascx中编写网络方法,以便轻松处理三页

预先感谢,
Vels



here i have used this test.ascx user control in three various aspx pages in another folder

in ADMIN folder
----------------
first.aspx
second.aspx
third.aspx

these three aspx pages having test.ascx

in USERCONTROL folder
----------------------
test.ascx

both ADMIN folder and USERCONTROL folder are in same path


problem is if i placed the webmethod in first.aspx.vb its working fine(it means i have to write the same code in three pages know). Instead of that i placed the webmethod in test.ascx.vb file means its not working.

Requirement is I need to write the webmethod in test.ascx it easy to handle three pages

Thanks in advance,
Vels

推荐答案

.ajax({ 类型:' POST', 网址:' test.ascx/GetRandomSalt', contentType:' application/json; charset = utf-8', 数据: {}, dataType:' json', 异步:错误, 成功:功能(r){ 结果= r.d; 文档 .getElementById(' <%= hdnRandomKey.ClientID %>').value =结果; 回调(结果); },错误:函数(x,e){ alertify.alert(" ) } });
.ajax({ type: 'POST', url: 'test.ascx/GetRandomSalt', contentType: 'application/json; charset=utf-8', data: {}, dataType: 'json', async: false, success: function (r) { result= r.d; document.getElementById('<%=hdnRandomKey.ClientID %>').value = result; callback(result); }, error: function (x, e) { alertify.alert("Server not responding, Please try again later.") } });



在这里,我已经在另一个文件夹中的三个不同的aspx页面中使用了这个test.ascx用户控件.

在ADMIN文件夹中
----------------
first.aspx
second.aspx
third.aspx

这三个具有test.ascx的aspx页面

在USERCONTROL文件夹中
----------------------
test.ascx

ADMIN文件夹和USERCONTROL文件夹都在同一路径中


问题是如果我将webmethod放置在first.aspx.vb中,它的工作是否正常(这意味着我必须在三页中编写相同的代码).取而代之的是,我将webmethod放在了test.ascx.vb文件中,这意味着它无法正常工作.

要求是我需要在test.ascx中编写网络方法,以便轻松处理三页

预先感谢,
Vels



here i have used this test.ascx user control in three various aspx pages in another folder

in ADMIN folder
----------------
first.aspx
second.aspx
third.aspx

these three aspx pages having test.ascx

in USERCONTROL folder
----------------------
test.ascx

both ADMIN folder and USERCONTROL folder are in same path


problem is if i placed the webmethod in first.aspx.vb its working fine(it means i have to write the same code in three pages know). Instead of that i placed the webmethod in test.ascx.vb file means its not working.

Requirement is I need to write the webmethod in test.ascx it easy to handle three pages

Thanks in advance,
Vels


这篇关于如何在Web用户控件中使用Ajax发布方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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