Server.Transfer/Response.Redirect cannot be called in a page callback

4 posts, 1 answers
  1. idwaikat
    idwaikat avatar
    25 posts
    Member since:
    Mar 2009

    Posted 06 Jul 2009 Link to this post

    Hi all

    I have a combobox as follows:


    <telerik:RadComboBox ID="cmbobox" runat="server" AutoPostBack="true" EnableLoadOnDemand="true"></telerik:RadComboBox> 


    Also I have the vb code:


    1 Protected Sub cmbobox_ItemsRequested(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles cmbobox.ItemsRequested 
    2   
    3         Dim objDataBaseClass As New DataBaseClass() 
    4         Dim dtDatabase As DataTable = objDataBaseClass.GetSomedataById(e.Text) 
    5   
    6         If dtDatabase Is Nothing Then 'or any other condition that checks for errors 
    7         'Here I need to go to error page: 
    8         'Response.Redirect("~/ErrorPage.aspx") 
    9         'Server.Transfer("~/ErrorPage.aspx") 
    10         End If 
    11   
    12         cmbobox.Items.Add(New RadComboBoxItem("""")) 
    13         For i As Integer = 0 To dtDatabase .Rows.Count - 1 
    14             cmbobox.Items.Add(New RadComboBoxItem(dtDatabase .Rows(i)("ID").ToString() & " - " & dtDatabase .Rows(i)("NAME").ToString(), dtDatabase.Rows(i)("ID").ToString())) 
    15         Next 
    16     End Sub 



    The problem is on lines (8 & 9), I am trying to go to another page to display some information about the error, but an exception thrown:

    Server.Transfer cannot be called in a page callback

    or

    Response.Redirect cannot be called in a Page callback

    I tired to register some client script like window.location but it does not work.

    Please can you give me some help???




  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 09 Jul 2009 Link to this post

    Hello idwaikat,

    You can throw new application exception in ItemsRequested event and subscribe to the OnClientRequestFailed event and redirect there:

    Protected Sub RadComboBox1_ItemsRequested(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs) Handles RadComboBox1.ItemsRequested         
            Throw New ApplicationException() 
        End Sub 

    <telerik:RadComboBox ID="RadComboBox1" runat="server"  
        OnClientItemsRequestFailed="onRequestFailed" 
        EnableLoadOnDemand="true"
    </telerik:RadComboBox> 
    <script type="text/javascript"
        function onRequestFailed(sender, e) { 
            e.set_cancel(true); 
            document.location.href = "ErrorPage.aspx"
        } 
    </script>  


    Best wishes,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Awadh .
    Awadh . avatar
    21 posts
    Member since:
    Nov 2009

    Posted 09 Jul 2010 Link to this post

    Hi Veselin,

    I am also facing similar problem, But my question is why this happening means root cause & why with rad controls ? Why not with regular .Net controls ?

    Because in my case, similar code was working fine earlier, but now giving same error whenever application tries to redirect to the error page.


    Thanks,
    Awadh
  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 09 Jul 2010 Link to this post

    Hello Awadh .,

    This is a generic error which lies in the ASP.NET Framework itself - Redirect of a page cannot happen while in an AJAX callback.

    Please see this thread for more info.

    Kind regards,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top