Differences using ajax or post back to post actions

≯℡__Kan透↙ 提交于 2019-12-11 11:37:52

问题


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".


回答1:


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.



来源:https://stackoverflow.com/questions/13239587/differences-using-ajax-or-post-back-to-post-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!