使用ajax或post回发帖操作的区别 [英] Differences using ajax or post back to post actions

查看:300
本文介绍了使用ajax或post回发帖操作的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的问题有点奇怪,因为我没有学习它(ajax方法)



我只是重用了一个原来的函数,我遇到,重命名和测试


$ b

一些< asp:TextBox> 控件,一个提交按钮。



Ajax对c#asp.net PostBack有什么好处?



这是代码

  function AppsName_AjxUpdt(CurrentColumn,recNumSplited, newValue,TBX,ActionRequest,RecordNum){
$ .ajax({
type:'POST',
url:'YourPageNameHere.aspx',
data:{
'PostSentByAjax':true,
'CurrentColumn':CurrentColumn,
'recNumSplited':recNumSplited,
'value':newValue,
'ActionRequest':ActionRequest
},
success:function(data){
// alert(data);
if(type ==UpdateUserID){
TBX.setAttribute(defaultValue, newValue);

refreshData();
}
if(type ==reason){
window.form1.submit();
}

if(type ==delete){
document.getElementById(row_+ rowid).style.display =none;
document.getElementById(totalMins)。innerHTML =< span style ='text-decoration:underline; color:#A7C942; cursor:pointer;'onclick ='refreshData();'> Refresh Results< ; / span>;
}
}
});
}

>< asp:TextBox> 到autopostback功能?
我可以说我做的笔记,...我可以看到的优势是:



只有当你想在标签中创建一个带有嵌入式c#代码的动态表,这样你可以生成 id name code> value 的属性,并且同时您希望该控件通过自己的事件回发(并且因为没有回发事件 html controls ),如果你在标签范围内应用了c#代码,那么在使用asp:TextBox时只能输入text。

解决方案

ASP.NET Postback 使页面经历完整的生命周期。
Ajax帖子是异步的,不会重新加载您的页面。在这个意义上,如果您使用Ajax调用发布帖子,则不会触发与页面生命周期相关的特定ASP.NET服务器事件。因此,您不会获得 Page_Init Page_Load 按钮或任何类似的东西。


So my question is a little weird, as I did not learn about it (ajax approach)

I just reused an original function that I encountered, renamed and tested the function.

So in other different scenario (more common):

A few <asp:TextBox> controls, one submit button.

What is the advantage of Ajax over c# asp.net PostBack?

This is the code

 function AppsName_AjxUpdt(CurrentColumn, recNumSplited, newValue, TBX, ActionRequest, RecordNum) {
        $.ajax({
            type: 'POST',
            url: 'YourPageNameHere.aspx',
            data: {
                'PostSentByAjax': "true",
                'CurrentColumn': CurrentColumn,
                'recNumSplited': recNumSplited,
                'value': newValue,
                'ActionRequest': ActionRequest
            },
            success: function (data) {
                //alert(data);
                if (type == "UpdateUserID") {
                    TBX.setAttribute(defaultValue, newValue);

                    refreshData();
                }
                if (type == "reason") {
                    window.form1.submit();
                }

                if (type == "delete") {
                    document.getElementById("row_" + rowid).style.display = "none";
                    document.getElementById("totalMins").innerHTML = "<span style='text-decoration:underline;color:#A7C942;cursor:pointer;' onclick='refreshData();'>Refresh Results</span>";
                }
            }
        });
    }

So how different is this code-behavior Vs binding an <asp:TextBox> to autopostback feature? I could just say what I did notes,...the advantage I could see is:

Only if you would like to create a dynamic table with embedded c# code within the tags so you could generate elements id's names and values properties, and in the same time you want that control to post back by it's own event(and since there's no postback event for html controls), and if you did apply c# codes within the scope of the tag it could not be while using an asp:TextBox only input type "text".

解决方案

The ASP.NET Postback makes the page undergo a full Page lifecycle. The Ajax post is asyncronous and does not reload your page. In this sense no specific ASP.NET server events related to the page lifecycle would be fired if you issue your post using an Ajax call. So you would not get Page_Init, Page_Load, Button clicks or anything like that.

这篇关于使用ajax或post回发帖操作的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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