[Sample of Apr 24th] How to add endRequest Event in updatepanel (ASP.NET)

 

Homepage image
Sample of the Day RSS Feed

Sample Downloads:
C# version: https://code.msdn.microsoft.com/AddEndRequestEventInUpdatep-f5142b04

VB version: https://code.msdn.microsoft.com/AddEndRequestEventInUpdatep-1a3eeb42  

Today’s code sample demonstrates how to add endRequest Event Support in UpdatePanel and resolve add_endRequest Event doesn't work in Firefox. Default page shows the scene of the current page using the ScriptManager Control. The WebForm1 page shows the scene, using the MasterPage which have already has the ScriptManager control, this page use the ScriptManagerProxy control. 

The sample was written by our star developer: Arwind Gao.

imageYou can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage https://1code.codeplex.com/.

 

Introduction

The sample demonstrates how to add endRequest Event Support in UpdatePanel and resolve add_endRequest Event doesn't work in Firefox. Default page shows the scene of the current page using the ScriptManager Control. The WebForm1 page shows the scene, using the MasterPage which have already has the ScriptManager control, this page use the ScriptManagerProxy control.

 

Running the Sample

Please follow these demonstration steps below.

Step 1: Open the CSASPNETAddEndRequestEventInUpdatepanel.sln.

Step 2: Right-click the Default.aspx page then select "View in Browser". Wait a moment, and then see the prompt.

Step 3: Right-click the WebForm1.aspx page then select "View in Browser". Wait a moment, and then see the prompt.

Step 4: Validation finished.

 

Using the Code

Step1. Create a C# "ASP.NET Web Application" in Visual Studio 2010/Visual Web Developer 2010. Name it as "CSASPNETAddEndRequestEventInUpdatepanel".

Step2. If you have installed SQL server 2008 r2 express on your computer, you can directly use the sample database under the App_Data. If not, add a SQL Server Database in the App_Data folder and name it as “SampleData”. The definition of the table "BooksScore” as show below:

[Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL, [Score] [float] NULL

You can insert the following test data or add new data:

 INSERT [dbo].[BooksScore] ([Id], [Name], [Score]) VALUES (1, N'HandBook', 80)  
INSERT [dbo].[BooksScore] ([Id], [Name], [Score]) VALUES (2, N'Guide', 90)  
INSERT [dbo].[BooksScore] ([Id], [Name], [Score]) VALUES (3, N'Story', 60.5)  
INSERT [dbo].[BooksScore] ([Id], [Name], [Score]) VALUES (4, N'HeadFirst', 70)  

Step3. Add two “Web Service” and a Master Page. Add two pages then rename to Default.aspx and WebForm1.aspx, the WebForm1 page uses the Master page created before.  Add a ScriptManager Control to the Default pages and the Master Page. Then to achieve the two services like the sample or you own code.

The main code of Master page as shown below:

 <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager" runat="server"> 
        <Services> 
            <asp:ServiceReference Path="~/WebService1.asmx" /> 
        </Services> 
    </asp:ScriptManager> 
     
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
        </asp:ContentPlaceHolder> 
     
</form>

The main code of WebForm1 page as shown below:

 <script src="Script/jquery-1.4.1.min.js" type="text/javascript"></script> 
 
 
 <asp:ScriptManagerProxy ID="iSmpSum" runat="server"> 
          <Services> 
              <asp:ServiceReference Path="~/WebService2.asmx" /> 
          </Services> 
      </asp:ScriptManagerProxy> 
 
 
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="false"> 
 
 
<Triggers> 
 
 
<asp:AsyncPostBackTrigger ControlID="LinkButton1" 
/> 
 
 
</Triggers> 
</asp:UpdatePanel> 
 
 
 <script type="text/javascript"> 
 $(document).ready(function() { 
          Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle); 
 
 
          function endRequestHandle(sender, Args) { 
              if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) 
 
 
  __doPostBack('LinkButton1', 
''); 
 
 
                
//alert test 
 
 
// 
var testGrid = $get('<%=grid1.ClientID %>'); 
 
 
// alert(testGrid.rows[1].cells[0].innerHTML); } 

}); 
</script>