Share via


UpdatePanel and Response.Redirect

Question

Wednesday, October 11, 2006 2:36 AM

I'm trying to get response.redirect to work when using updatepanel.

Looking at Fiddler, it appears that a 302 is return and the new page is sent, however Atlas simply pops the "Unknown Error" alert or shows the ErrorTemplate.

Does anyone have any suggestions as to what may be going on here? 

All replies (10)

Friday, October 13, 2006 3:38 AM

As there is no real 'Response', methods like Response.Redirect and Response.Write will not work with atlas

You can try javascript redirect: 

Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect", "location.href = 'SomePage.aspx'", true);

 


Friday, October 13, 2006 7:09 AM

Although you are right while saying that Response.Write don't work for example in UpdatePanel, you are wrong when you say that  Resonse.Redirect  doesn't work. It works perfectly for me.

Check this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
       
       
        <atlas:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button runat="server" ID="Button1" Text = "Click me" OnClick="Button1_Click" />
            </ContentTemplate>
        </atlas:UpdatePanel>
    </form>
</body>
</html>

 

protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }


Friday, October 13, 2006 7:24 AM

When you say it works, what does that mean.

A Response.Redirect() works in that it does a response redirect on the callback. But I doubt that's what you would expect <s>... Most likely you'd want to redirect the full page not the callback.

 


Friday, October 13, 2006 8:01 AM

It works because another page  is displayed and the old one is "closed".

I don't understand why is this callback redirect a problem. Do you have some link so I can learn more about it? 


Wednesday, November 1, 2006 5:22 AM

Hello,

i had my testing login page like this and it returning error when i m redirecting to some page.

Login.aspx.vb

Partial Class login

Inherits System.Web.UI.Page

Private Sub CheckLogin()

If txtLogin.Text = "admin" And txtPass.Text = "12345" Then

Session.Add("Login", txtLogin.Text)

Session.Add("Pass", txtPass.Text)

'Response.Redirect("default.aspx", True)

Else

Session.Add("Login", txtLogin.Text)

Session.Add("Pass", txtPass.Text)

'Response.Redirect("default2.aspx", True)

End If

End Sub

Private Sub ClearFields()

txtLogin.Text = ""

txtPass.Text = ""

txtLogin.Focus()

End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click

System.Threading.Thread.Sleep(500)

CheckLogin()

End Sub

Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click

System.Threading.Thread.Sleep(200)

ClearFields()

End Sub

End Class

Login.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="login.aspx.vb" Inherits="login" %>

<%@ Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="Microsoft.Web.UI.Controls" TagPrefix="asp" %>

<%@ Register Assembly="Microsoft.Web.Preview" Namespace="Microsoft.Web.Preview.UI"

TagPrefix="asp" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="True" runat="server">

</asp:ScriptManager>

<div>

<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">

<ContentTemplate>

<table>

<tr>

<td style="width: 100px">

<asp:Label ID="lblLogin" runat="server" Text="Login :"></asp:Label></td>

<td style="width: 100px">

<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox></td>

</tr>

<tr>

<td style="width: 100px">

<asp:Label ID="lblPassword" runat="server" Text="Password :"></asp:Label></td>

<td style="width: 100px">

<asp:TextBox ID="txtPass" runat="server" TextMode="Password"></asp:TextBox></td>

</tr>

<tr>

<td colspan="2" style="height: 21px">

</td>

</tr>

<tr>

<td colspan="2">

<asp:Button ID="btnLogin" runat="server" Text="Login" />

 <asp:Button ID="btnReset" runat="server" Text="Reset" /></td>

</tr>

</table>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />

</Triggers>

</asp:UpdatePanel>

 

<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="Panel1" DisplayAfter = "10" runat="server">

<ProgressTemplate>

<img src="image/indicator.gif" />

<br />

loading..

<br />

<img src="image/indicator_mozilla_blu.gif" />

</ProgressTemplate>

</asp:UpdateProgress>

<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton></div>

</form>

</body>

</html>


Wednesday, November 1, 2006 1:28 PM

1) Response.Redirect is supported in atlas.
2) I tried the sample code you provided  without the assemblies Microsoft.Web.Preview and AjaxControlToolkit
    and it worked fine for me. I have not tried by including the two mentioned assemblies.

vineetc

 

 


Thursday, November 2, 2006 1:18 AM

hmmm..i had posted my full code..act the main thing i wanna do is to hav the update progress run before redirecting to another page..

it is running well with the segment below :anyone know how to let the UpdateProgress appear before redirecting?

<Triggers>

<asp:PostBackTrigger ControlID="btnLogin" />

</Triggers>

anyone know how to let the UpdateProgress appear before redirecting? Thanks in advance


Tuesday, November 20, 2007 7:13 AM

Response.Redirect work fine with properly configured AJAX extensions 

Response.Redirect will not work without this in web.config. 

           <httpModules>
               <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </httpModules>
 


Tuesday, November 20, 2007 10:32 PM

See this when we used Response.Write() with UpdatePanel

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx


Saturday, November 15, 2008 3:00 AM

Hi All

You can't call response.redirect during the page callbacks. So you can use the following solution

We can use the asp timer control as follows
 
<asp:Timer ID="tmCheckStatus" Interval="1800000" runat="server">
</asp:Timer>
 
where the intervel is in millisecconds
 
In the event section we can write the following
 
Protected Sub tmCheckStatus_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmCheckStatus.Tick
        If Session("abc") = Nothing Then
               Response.Redirect("Login.aspx")
        End If
End Sub

So in this way as soon as the session is expired. User will be redirected to the Login Page thus avoiding the user to click on page when the session is expired.

Mudassar Khan