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