tags:

views:

2192

answers:

4

Hello, I have a problem: when i call a Response.Redirect() from the MasterPage it doesn't work. Well, debugging i can see that until the Pre_Render() method the target page is loaded, but then is rendered the previous page.

Here's some code to better explain:

(from MasterPageMain.master.cs)

protected void Page_Init(object sender, EventArgs e)
{
    string m_QueryStringValue = Request.QueryString.Get("action");
    if ((!string.IsNullOrEmpty(m_QueryStringValue)) && (m_QueryStringValue.ToLower() == "send"))
    {
        if (Session["to"] != null && Session["to"] is List<string>) this.SendPageByMail();
        else
        {
            Session.Add("AddressToSend", Request.RawUrl);
            Response.Redirect("~/chooseRecipients.aspx");
        }
    }
}

I have a javascript that adds the querystring adding "action=send" when i click on the Send button.

If i am on page "~/somethingInterestingToSend()" -for example- i want to get on the recipient selection page, but when i click the Send button i see always the same page.

What coul be the mistake?

A: 

I don't know if its the root of your problem but I'd change 2 things. I'd change your code to:

Response.Redirect("~/chooseRecipients.aspx", false);

and move the logic to PageLoad

Echostorm
+1  A: 

I am not sure I fully understand your description of the problem, but here are a few things to consider:

You mention a send button. If this is an , clicking it fires a javascript postback to the server. This postback is to the original URL. I'm not sure what you are modifying with Javascript, but I don't think it would change the postback URL (and querystring).

If you need to perform logic to redirect you might want to execute in the button click event on the server.

If you don't need to execute any logic on the server, you could to the redirect with javascript:

window.location = "chooseRecipients.aspx";
HectorMac
+1  A: 

@Echostorm: i tryed but it doesn't work.. same behavior :/

@HectorMac: unfortunately i have some logic to execute; i could redirect from javascript if it is possible to add something to Session from js..

p.s. i know this should be a comment but i can't comment yet

voting you up so you can comment
Eduardo Molteni
+1  A: 

Can't test this theory (running from memory at the moment), but give this a shot:

(sorry, cleaned up the code a bit as well)

protected void Page_Init(object sender, EventArgs e)
{
    string m_QueryStringValue = Request.QueryString.Get("action") ?? "";
    if (m_QueryStringValue.ToLower() == "send")
    {
        if ( (Session["to"] as List<string>) != null) 
        {
            this.SendPageByMail();
        }
        else
        {
            Session.Add("AddressToSend", Request.RawUrl);
            Response.Redirect("~/chooseRecipients.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest()
        }
    }
}
JerKimball
sorry, doesn't work