2012年3月26日月曜日

Response.Redirect cannot be called in a page callback error message.

Hi. I'm using the Dundas Chart Controls in VS 2005. These controls are built utilizing AJAX. I have a basic page with a dundas chart control containing a funnel chart. The funnel contains Quotes, Sales Orders and Invoices. When the user clicks on the control, I want to determine whether they clicked on Quotes, Sales Orders or Invoices and transfer to the appropriate Details Page. I've got the code working to determine which transaction type they clicked on; but, I get the "Response.Redirect cannot be called in a page callback." error when the page tries to redirect. Note: I get a similar issue if I try server.transfer.

Suggestions?

Here's my code:

Dim hitTestResultAs Dundas.Charting.WebControl.HitTestResult = Chart1.HitTest(e.X, e.Y)If Not (hitTestResultIs Nothing)Then Dim clickedAs Dundas.Charting.WebControl.DataPoint = hitTestResult.Series.Points(hitTestResult.PointIndex)Select Case hitTestResult.PointIndexCase 0 Response.Redirect("COQuotes.aspx")Case 1 Response.Redirect("COOrders.aspx")Case 2 Response.Redirect("COOrders.aspx")End Select End If

Since it's a partial postback that is occuring, you can't use Response.Redirect. You need to do a full postback in order to redirect or use a different method. See the last message in this post:http://forums.asp.net/t/1165851.aspx

-Damien


I have no control over the callback. It is being executed by the Dundas Control. I tried implementing the code with the RegisterClientScript, as below. But, nothing happens...

Dim hitTestResultAs Dundas.Charting.WebControl.HitTestResult = Chart1.HitTest(e.X, e.Y)If Not (hitTestResultIs Nothing)Then Dim clickedAs Dundas.Charting.WebControl.DataPoint = hitTestResult.Series.Points(hitTestResult.PointIndex)Select Case hitTestResult.PointIndexCase 0 clientRedirect("COQuotes.aspx")Case 1 clientRedirect("COOrders.aspx")Case 2 clientRedirect("COOrders.aspx")End SelectSub clientRedirect(ByVal URL)Dim jScriptAs String jScript =String.Format("document.location.href ='{0}');", URL) ClientScript.RegisterClientScriptBlock(Page.GetType(), "redirect", jScript,True)End Sub


GiveRegisterStartupScript a try. Seehttp://blogs.ittoolbox.com/c/coding/archives/registerclientscriptblock-and-registerstartupscript-17321 for some more info.

-Damien


Tried RegisterStartupScript, still nothing happens.

Jennifer


Hi,

I'm not familiar with dundas chart but is there no way to setup a href on a chart element during rendering? I would have thought this would be a standard feature.

Back to your Response.Redirect problem. When you get a response from the callback can you control the client-side callback function? If so you could use the cookie method as in the last post. If you have no control over the client-side callback function I very much doubt your going to be able to add the functionality you require.

One minor point, if your re-directing anyway whay do you need to use ajax, you could do a page post back when clicking the chart, do your logic and then redirect. To the user the behavior would seem exactly the same as your moving to a different page anyway.

Cheers Si


You won't be able to use Response.Redirect() or Server.Transfer() in a callback, check if the control has a client event you can use instead, if that event exists you could use window.location.replace("OtherPage.aspx"); using JavaScript from the client to move to another page.

0 件のコメント:

コメントを投稿