Asp.net controls are asynchronously refreshed and asp.net controls are asynchronously refreshed.

Source: Internet
Author: User

Asp.net controls are asynchronously refreshed and asp.net controls are asynchronously refreshed.

Requirement: We know that auto-send is enabled by default for the button control in the asp.net control. Sometimes, we don't want to refresh the entire interface, but only want to refresh it locally, but it is also used on the page. net button control.


Although I hate. net controls very much, sometimes, in the case of low system performance requirements, it is understandable to use. net controls for laziness.
Aspx page code (only key code is written ):

<Asp: Button ID = "<span style =" color: # FF0000; "> btnSearch </span>" runat = "server" Text = "Search" OnClick = "btnSearch_Click"/> <asp: scriptManager ID = "ScriptManager1" runat = "server"> </asp: scriptManager> <div id = "divRecordList" class = "rptCss"> <% -- <div> <span> select </span> <span> customer name </span> <span> Customer Code </span> <span> water meter Code </span> </div> -- %> <div> <table style = "width: 100%; "> <tr class =" order-hd "> <th class =" item "style =" wid Th: 96px; "> select </th> <th class =" item "style =" width: 200px; "> customer name </th> <th class =" item "style =" width: 200px; "> Customer Code </th> <th class =" last "style =" width: 200px; "> water meter Code </th> </tr> </table> </div> <asp: updatePanel ID = "UpdatePanel1" runat = "server"> <Triggers> <span style = "color: # FF0000;"> <asp: asyncPostBackTrigger ControlID = "btnSearch"/> </span> </Triggers> <ContentTemplate> <asp: Panel ID = "pnlNullInfo" runa T = "server" CssClass = "tb-combobar" Visible = "false"> <div class = "item-not-found"> <asp: label ID = "lblNullInfo" runat = "server" Text = "no data found"> </asp: Label> </div> </asp: Panel> <asp: panel ID = "pnlError" runat = "server" Visible = "false"> <asp: Label ID = "lblError" runat = "server"> </asp: label> </asp: Panel> <asp: Repeater ID = "rptRecordList" runat = "server"> <HeaderTemplate> <table style = "width: 100%;"> </HeaderT Emplate> <ItemTemplate> <tr class = "order-item"> <td style = "width: 96px;" class = "item"> <span style = "margin-right: 4px; "> <% # Container. itemIndex + 1%> </span> <input type = "radio" id = "rbtn1" value = '<% # Eval ("hx_t_watermeterid ") %> '/> </td> <td style = "width: 201px;" class = "item"> <% # Eval ("name ") %> </td> <td style = "width: 200px;" class = "item"> <% # Eval ("accountnumber ") %> </td> <td style = "width: 200px;" linoleic Ss = "last"> <% # Eval ("hx_fmetercode ") %> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp: repeater> <div id = "divError" class = "errorDiv"> <span id = "spnError"> </span> </div> </ContentTemplate> </asp: updatePanel> </div> <div class = "menu"> <ul> <li id = "one1" onclick = "setTab ('one', 1) "> recharge </li> <li id =" one2 "onclick =" setTab ('one', 2) "> Cancel water sales </li> <li id =" one3 "onclick =" setTab ('one', 3) "> Retreat </li> <li id = "one6" onclick = "setTab ('one', 6) "> change table </li> </ul> </div> <div class =" menu "style =" border-top: # cccccc solid 1px; "> <ul> <li id =" one4 "onclick =" setTab ('one', 4) "> card supplement </li> <li id =" one5 "onclick =" setTab ('one', 5); clearCardExt (); "> clear cards </li> <li id =" one7 "onclick =" setTab ('one', 7); readCardExt (); "> card reading </li> </ul> </div> <! -- Record the status of the operation tab --> <asp: HiddenField ID = "<span style =" color: # FF0000; "> hidfTagHistory </span>" runat = "server" Value = "1"/>
Js Code:
// Record the status function recorverTag () {var cur = document. getElementById ("<span style =" color: # FF0000; "> hidfTagHistory </span> "). value; setTab ("one", parseInt (cur ));}

Cs code:

// Query protected void btnSearch_Click (object sender, EventArgs e) {string searchTag = hidfSearchTag. value; string words = txtWords. text. trim (); DataTable dt = null; switch (searchTag) {case "0": // water meter code dt = SearchInfoListByMeterCode (words); break; case "1 ": // Customer Code break; case "2": // customer name break; default: break;} if (dt = null | dt. rows. count = 0) {pnlNullInfo. visible = true;} else {pnlNullInfo. visible = false;} rptRecordList. dataSource = dt; rptRecordList. dataBind (); // clear the detailed information of the customer ScriptManager. registerStartupScript (UpdatePanel1, this. getType (), "scriptKey", "clearAccountInfo () <span style =" color: # FF0000; "> <span style =" color: #000000; ">; </span> recorverTag (); </span> ", true );}




When the aspnet user control droplist is selected, the entire page is refreshed. I wrapped it in UpdatePanel, and it doesn't work either. How can I achieve asynchronous refresh?

When you use the updatePanel package, is there an attribute not set. I forgot, as if it was Triggers: a partial update trigger, which includes AsyncPostBackTrigger for partial update. Both PostBackTrigger and normal one-stop operations may cause all page updates, regardless of whether a partial update control is used.

The ajax control of aspnet partially refreshes the source file.

Indeed, to solve this problem, you must be proficient in the asp.net ajax structure.

But now I want to help you solve the problem.
First, you need to know that the function of the entire asp.net ajax framework is to control the postback of the form on the whole page. If the postback control is the asyncpostback control, asynchronous submission is executed, otherwise, the default synchronous submission is executed.
If you need to update updatepanel asynchronously, you must register the current control for asynchronous submission.

If your control exists on the original server, it is easy to write code on the server side. In the current ScriptManager, you can call RegisterAsyncPostBackControl or add the UpdatePanel Trigger.
If your control is created independently by the client, you may need to write a custom control and register it as Asynchronous, and save his ClientId to the page of the return value client. You need this id to mark the currently returned control, A button dynamically generated on the page needs to call a method like this during onclick _ doPostBack ('your control clientid ', 'parameters such as the task to be executed by the current Button '), but it is safer to obtain such a script from GetPostBackScript of ClientScript on the Page. Maybe the asp.net framework will change this script in the future.
In this way, when the dynamically generated button is clicked, it is equivalent to the custom control postback you wrote. If it is submitted asynchronously, it will drive updatepanel for updates.

Hope to help you. If you have any questions, please send me hi.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.