Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of examples caused by partial updates of .net pages

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about the sample analysis caused by the partial update of the .net page. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. UpdatePanel

Put the modules that need to be updated into the ContentTemplate of UpdatePanel, and the postback in the area will not refresh the entire page. And the content of the response is only the updated content in UpdatePanel.

Such as: inquiry

ID name age address entry date departmental salary

Using UpdatePanel can achieve local updates without writing any asynchronous request code, but the performance will have a certain impact, and the flexibility and reusability are not high.

2.Ajxa and general handlers

First of all, create a new general handler, receive the query parameters, return the employee information after the query, and return all the information by default.

Such as: inquiry

P >

Using Ajax queries is flexible, but the stitching of html code is a bit annoying, and there are certainly many ways to improve it. Let's continue with the introduction.

Function ajaxquery () {$.ajax ({url: "/ DataService/getEmployee.ashx", type: "GET", cache: false, data: {key: $("# ajaxkey"). Val ()}, dataType: "json", success: function (data, textStatus) {if (data.code = = "ok") {$("# ajaxtable tr.row"). Remove (); var html = ""; for (var I = 0; I < data.res.length) ID + "" + data.res [I] .ID + "" + data.res [I] .Name + "" + data.res [I] .Age + "+ data.res [I] .Address +"+ data.res [I] .JoinDate +"+ data.res [I] .Department +" + data.res.Salary + ""} if (html = "") html + = "there are no records, please improve the query conditions" $("# ajaxtable") .append (html);} else {alert (data.info);}}, error: function (XMLHttpRequest, textStatus, errorThrown) {alert ("Network is busy, please refresh the page!") ;}})

3. Avalonjs improves code splicing

Angularjs is also used a lot, but it is too large, so find an Avalonjs that is more suitable for general development.

I have asked such a question in the blog before: is there a plug-in for two-way binding of jquery data, which is dirty to check? Just to discuss with you, I have seen a DataSet js plug-in, all the data in the form of json binding DataSet,DataSet itself to achieve dirty checking, the rest of the controls are bound to a property of the corresponding DataSet. As long as the value of a bound control changes, you can get only the changed data from the DataSet (not the entire json). The answer is almost Angularjs. It is also a basic two-way binding, so dirty checking still has to be implemented on its own.

Use Avalonjs to first introduce the js file, and then define the controller

Such as: inquiry

ID name, age, address, entry date, department salary {{emp.ID}} {{emp.Age}} {{emp.JoinDate}} {{emp.Department}} var vm = avalon.define ({$id: "avalonCtrl", emps: [], key: "" Query: function () {$.ajax ({url: "/ DataService/getEmployee.ashx", type: "GET", cache: false, data: {key: vm.key}, dataType: "json", success: function (data, textStatus) {if (data.code = = "ok") {vm.emps = data.res } else {alert (data.info);}}, error: function (XMLHttpRequest, textStatus, errorThrown) {alert ("Network is busy, please refresh the page!") ;}})

Finally, back to dirty check: if you improve this to an editable table, how do you listen to which rows are modified, and instead of submitting the entire table data when saving, you should submit the modified row data?

Thank you for reading! This is the end of this article on "sample Analysis caused by partial updates of .net pages". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report