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

RebindAndClose after response.binaryWrite

2 Answers 203 Views
Window
This is a migrated thread and some comments may be shown as answers.
mac
Top achievements
Rank 1
mac asked on 20 Jan 2011, 01:14 AM
Scenario: UserControl on Parent has RadwindowManager that launces RadWindow. RadWindow has ReportViewer with button to save save file and BinaryWrite to PDF.
PROBLEM: when user clicks Save File, it launches into the sub but glosses over the script. I can confirm that it works fine when I get rid of the binaryWrite stuff, it postsback to the parent fine.
How can I make it so that when I click SaveFile, it will write the report to PDf, Save it to disc, create a record in db, and refresh the parent window... so close!

Code:
Usercontrol: Removed instances of RadajaxProxy for debugging
  <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Label ID="Time" runat="server"></asp:Label>
   
       <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        
      <script type="text/javascript">
     function refreshGrid(arg) {
    var btn = document.getElementById("<%=Button1.ClientID %>")
   btn.click();
    }
  
      
    function OnClientSelectedIndexChanging(sender, args) {
        //   var text = args.get_item().get_text();  
        // Prepare the url and Open the window by setting the url  
        var text = args.get_item().get_text();
        var RouteID = document.getElementById("<%=RouteID.ClientID %>").innerText;
        var url = "ReportShell.aspx?value=" + text + "&RouteID=" + RouteID;
        radopen(url, '');
    }  
  
  
'CODE
  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Time.Text = DateTime.Now.ToBinary.ToString
        
    End Sub
  
     </script>
         </telerik:RadCodeBlock>

Radwindow aspx page:
<script type="text/javascript">
          function CloseAndRebind(args) {
              GetRadWindow().BrowserWindow.refreshGrid(args);
              GetRadWindow().close();
          }
          function GetRadWindow() {
              var oWindow = null;
              if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
              else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
              return oWindow;
          }
       </script>
   
       <br /><asp:Button ID="SaveBtn" Text="Save File" runat="server" />
    
       <rsweb:ReportViewer ID="ReportViewer1" ShowToolBar="false"  runat="server" Font-Names="Verdana" 
           Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
       </rsweb:ReportViewer>

Radwindow.aspx.VB CODE:
Protected Sub SaveBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
       Dim extension As String = "pdf"
       Dim mimetype As String = "application/pdf"
       Dim mybytes As Byte() = ReportViewer1.LocalReport.Render("PDF", Nothing, mimetype, Nothing, extension, Nothing, Nothing)
       Response.Buffer = True
       Response.Clear()
       Response.ContentType = mimetype
       Dim fn As String = DateTime.Now.ToBinary & Request.QueryString("RouteID").ToString & "." & extension 'Create a filename
       Response.AddHeader("content-disposition", "attachment; filename=" & fn)
       Response.BinaryWrite(mybytes)
       Dim fp As String = Server.MapPath(String.Format("Files/{0}", fn)) ' set filepath
       'stick it into the files datatable -- need to capture the routeid, filename
       BaseFunctions.Scalar(String.Format("Insert into TBL_docs(Route_ID, Doc_name, Doc_path) Values ({0},'{1}','{2}')", Request.QueryString("RouteID"), fn, fp))
       Dim fs As FileStream = New FileStream(fp, FileMode.CreateNew) ' write the file to disc
       fs.Write(mybytes, 0, mybytes.Length)
       fs.Close()
       runscript("fn") ' The script to update the parent and close the window
       Response.Flush()
       Response.End()
   End Sub
 Sub runscript(ByVal fp As String)
       Dim sb As StringBuilder = New StringBuilder
       sb.Append("<script type='text/javascript'>" & vbCrLf)
       sb.Append("CloseAndRebind('" & fp & "');")
       sb.Append("</script>" & vbCrLf)
       ClientScript.RegisterStartupScript(Page.GetType(), "RebindMe", sb.ToString)
End Sub

Please let me know. I have no idea how to work around it other than posting the page back, but that is a whole other set of issues.
mac





2 Answers, 1 is accepted

Sort by
0
mac
Top achievements
Rank 1
answered on 21 Jan 2011, 07:03 PM
I could really use a hand on this as I cannot see how to work around it. if I hook the RebindAndClose event onClientClick, the OnClick event is bypassed.
0
Georgi Tunev
Telerik team
answered on 24 Jan 2011, 03:31 PM
Hi Mac,

In your code you are changing the type of the content to PDF - from this point on you are not working with an aspx page, but with a PDF file - that is why the script is not working. I would suggest to consider changing your logic and to output the PDF in a different page.


All the best,
Georgi Tunev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Window
Asked by
mac
Top achievements
Rank 1
Answers by
mac
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or