Asynchronous requests for server controls--updatepanel and ScriptManager

Source: Internet
Author: User

The following code is in the ASPX file

<body>    <form id="Form1" runat="server">        <div>            <%=datetime.now%>            <uc1:usercontrol runat="server" id="UserControl" />        </div>    </form></body>

Note: UserControl1 is an external drag-and-drop DropDownList user control that can trigger a page refresh when switching options, and can be replaced by other controls, as long as the refresh is triggered.

What is the effect of the operation? Because the fetch time and the thread of the user control are synchronized , each switch to the user control will change the time displayed on the page.

So how do you make the user control operation not refresh the entire page, but just refresh yourself? (This is a bit of a mouthful, it is understood as the DropDownList option to switch when the others remain the same without refreshing the line)

Here you can use two server controls to achieve your goal: UpdatePanel and ScriptManager

We try to insert a few lines of code on top of the above, noting the difference between the two code:

<body> <form id="Form1"runat="Server"> <div> <%=datetime.now%> <asp:scriptmanager id="ScriptManager1"runat="Server"></asp:ScriptManager> <asp:updatepanel id="UpdatePanel1"runat="Server"> <ContentTemplate> <uc1:usercontrol runat="Server"Id="UserControl"/> </ContentTemplate> </asp:UpdatePanel> </div> </form>< /body>

I first added a ScriptManager and then wrapped the DDL control with a UpdatePanel

Note:<contenttemplate> 's role is to define the content template of the update panel, that is, the content that is placed here is required to be updated

What is the effect of this operation?

No matter how the option to toggle the dropdown box, it will not cause the time on the page to change.

The reason is that after this process, the drop-down box user control option changes to an asynchronous request, does not refresh the entire page, so the previous time is not retrieved, so it does not change

Finish

Asynchronous requests for server controls--updatepanel and ScriptManager

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.