Giorgos Manoltzas
Giorgos Manoltzas

Reputation: 71

Page_Load not firing after Response.Redirect in ASP.NET

in a asp.net application i have a form, and after a user clicks a button i use Response.Redirect to go to another page. But in the second page the Page_Load event is not firing. I have tried to set AutoEventWireup="false. Also i have tried to clear the cache of the browser and last i tried to use this.Load event handler but the result is the same. Any help is appreciated.

Thanks in advance and merry Christmas!

/Added the code/

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        CreateXML();
        PostToWebApplicationB();
        Response.Redirect(url);
    }

/This is PostToWebApplicationB method/

private void PostToWebApplicationB()
    {
        try
        {
            request = WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "text/xml";

            StreamWriter writer = new StreamWriter(request.GetRequestStream());
            writer.WriteLine(this.GetTextFromXmlFile(filepath));
            writer.Close();
            response = request.GetResponse();
        }
        catch (Exception ex)
        {
            errorLabel.Text = ex.Message;
        }
        finally
        {
            if (request != null)
            {
                request.GetRequestStream().Close();
            }
            if (response != null)
            {
                response.GetResponseStream().Close();
            }
        }
    }

/Directive of destination page/

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Intermediate.aspx.cs"
Inherits="WebApplicationB.Intermediate" %>

Upvotes: 0

Views: 3505

Answers (1)

Keith
Keith

Reputation: 5381

Either set AutoEventWireup="true" and make sure you have a method on the page that matches the Page_Load(object sender, EventArgs e) signature

-OR-

Keep AutoEventWireup="false", but make sure you then bind the OnLoad event to a method manually.

C# Example:

override protected void OnInit(EventArgs e)
{
    this.Load += new System.EventHandler(this.Page_Load);
}

Upvotes: 2

Related Questions