This is a migrated thread and some comments may be shown as answers.

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

3 Answers 302 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
idwaikat
Top achievements
Rank 2
idwaikat asked on 06 Jul 2009, 12:46 PM
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:


Protected Sub cmbobox_ItemsRequested(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles cmbobox.ItemsRequested 
  
        Dim objDataBaseClass As New DataBaseClass() 
        Dim dtDatabase As DataTable = objDataBaseClass.GetSomedataById(e.Text) 
  
        If dtDatabase Is Nothing Then 'or any other condition that checks for errors 
        'Here I need to go to error page: 
        'Response.Redirect("~/ErrorPage.aspx") 
        'Server.Transfer("~/ErrorPage.aspx") 
        End If 
  
        cmbobox.Items.Add(New RadComboBoxItem("""")) 
        For i As Integer = 0 To dtDatabase .Rows.Count - 1 
            cmbobox.Items.Add(New RadComboBoxItem(dtDatabase .Rows(i)("ID").ToString() & " - " & dtDatabase .Rows(i)("NAME").ToString(), dtDatabase.Rows(i)("ID").ToString())) 
        Next 
    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???




3 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 09 Jul 2009, 09:42 AM
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.
0
Awadh .
Top achievements
Rank 1
answered on 09 Jul 2010, 12:23 PM
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
0
Simon
Telerik team
answered on 09 Jul 2010, 01:00 PM
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
Tags
ComboBox
Asked by
idwaikat
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Awadh .
Top achievements
Rank 1
Simon
Telerik team
Share this question
or