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
Radwindow aspx page:
Radwindow.aspx.VB CODE:
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
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