Server.Execute() does not wait for the second aspx page to finish executing?

Multi tool use
Multi tool use


Server.Execute() does not wait for the second aspx page to finish executing?



I have an aspx page that executes another aspx page through Server.Execute() since I need the called aspx page to postback in order to grab a session variable. However, I have noticed in my code that when the Server.Execute() is called, it does not wait for the called page to load up and posback, the code just goes on and the page is only loaded after the function is finished? Does anyone know how to fix this? Below is the code I am using in the parent page to call the page I want to load.


Imports System.IO

Public Class TriggerPage
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Server.Execute("SvgForm.aspx", False)
'This variable is only populated after the SvgForm.aspx executes and posts back since the Session variable is initialized there
Dim htmlCode As String = Session("svgVariable")
End Sub

End Class



Aspx page code:


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TriggerPage.aspx.vb" Inherits="TelerikChart.TriggerPage" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body onload="openWindow()">
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
</asp:ScriptReference>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
</asp:ScriptReference>
</Scripts>
</telerik:RadScriptManager>


<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function openWindow() {
window.open('svgForm.aspx'); return false;
}

function RefreshParentPage() {
document.location.href = document.location.href;
}
</script>
</telerik:RadScriptBlock>
</div>
</form>
</body>
</html>





Looks like VB to me, not C#
– TigOldBitties
Jul 24 '14 at 20:22





asp.net is the same concept...
– LeBron James
Jul 24 '14 at 20:23





Why is this question tagged with telerik and javascript?
– Rick S
Jul 24 '14 at 20:24





because the all telerik graphs are rendered as SVG and this is what I am grabbing and the postback is specifically related to javascript.
– LeBron James
Jul 24 '14 at 20:24





What makes you think that it's not waiting for the called page to finish? If you're expecting the session variable to be set it won't be. Server.Execute() is a completely different process therefore a new Session.
– Rick S
Jul 24 '14 at 20:31





1 Answer
1



Tyger,



You are going about this wrong. This is how one captures the output html of a Server.Execute command:


Dim sw As New StringWriter()
Server.Execute("SvgForm.aspx", sw)
Dim htmlCode As String = sw.ToString



Be careful about passing data around as session variables. I think I ran into troubles because Server.Execute() seems to cache replies into the context of the current session. So subsequent changes to session variables may not lead to subsequent changes of the content generated by Server.Execute(), at least in the scope of the current user. Although empirical, this is the only viable explanation for some rather crazy behavior I've seen. Safer might be to append a random to the requested URI, to bust the cached session (user) specific response.


Server.Execute("SvgForm.aspx?rand=" & MyRandomNumberGenerator(), sw)



I'm going to test this theory to find out for sure...






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

R70BS7QP7
T6Chd,iHD7k e,9w1YeNKTmqfnDC7gbSS6C,e8,EcJa3GTdGIvI,TUuxKi U6oXMbCSNmTHehlA4 buzeKRtuQ29 hOBD4CTdaK6,Th 7 D,G

Popular posts from this blog

Rothschild family

Cinema of Italy