Note that there are some explanatory texts on larger screens.

plurals
  1. POCode executes even after Response.End()
    primarykey
    data
    text
    <p>I have to reload my page after I write some html, script to my page using Response.Write. After using Response.Write I am using Response.Flush(), followed by Response.End(). The code works properly in one server and when I deploy it to another server it is not working. As far as I know the code execution must stop once it executes the Response.End, but it is now behaving in the desired way.</p> <pre><code>Response.ClearContent(); Response.Write("Write some html, script content here"); Response.Flush(); Response.End(); </code></pre> <p>Using Respose.Redirect(Request.RawUrl) will not work and will throw an exception stating that the redirection cannot happen once the headers are posted...</p> <p>Can some one tell me, why the code execution is not stopped by Response.End() ??</p> <p>EDIT: Actual Code</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { if (Session["localTime"] == null &amp;&amp; String.IsNullOrEmpty(Request.Params["localTime"])) { // then clear the content and write some html, a javascript code which submits the local time Response.ClearContent(); Response.Write(@"&lt;form id='local' method='post' name='local'&gt; &lt;input type='hidden' id='localTime' name='localTime' /&gt; &lt;script type='text/javascript'&gt; document.getElementById('localTime').value = new Date(); document.getElementById('local').submit(); &lt;/script&gt; &lt;/form&gt;"); // Response.Flush(); // end the response so PageLoad, PagePreRender etc won't be executed Response.End();//Page must reload after this line. } else { // if the request contains the localtime, then save it in Session if (Request.Params["localTime"] != null) { Session["localTime"] = Request.Params["localTime"]; Response.Write(Request.Params["localTime"] + " ~2"); // and redirect back to the original url Response.Redirect(Request.RawUrl); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload