Postback edited Report on button-click
Postback edited Report on button-click
My goal is to create a report in an Asp-MVC-project, that renders in a standard browser and that has several fields (as part of the report), that the user can fill in (like a form) and then send back to the server.
I don’t want to use the build-in save and export menu but instead display my own Postback-Button to make it easier for the user.
In short, I want to postback an edited report on button-click.
Can you provide me sample or code that could help me in this task?
I don’t want to use the build-in save and export menu but instead display my own Postback-Button to make it easier for the user.
In short, I want to postback an edited report on button-click.
Can you provide me sample or code that could help me in this task?
Re: Postback edited Report on button-click
Hi Scotty,
If I understood the question correctly, then you would like to render the report result without using the report viewer?
That is possible to achieve if you would like not to use our standard dialogue forms to send the parameters to your report as follows:
https://www.youtube.com/watch?v=u6F3nbG5RLE
viewtopic.php?f=13&t=5779
And then to send the report result to the user, without using the report viewer, as per the following sample:
https://www.stimulsoft.com/en/samples/m ... -from-code
Please let us know if you need more details on how to implement that.
Thank you,
Edward
If I understood the question correctly, then you would like to render the report result without using the report viewer?
That is possible to achieve if you would like not to use our standard dialogue forms to send the parameters to your report as follows:
https://www.youtube.com/watch?v=u6F3nbG5RLE
viewtopic.php?f=13&t=5779
And then to send the report result to the user, without using the report viewer, as per the following sample:
https://www.stimulsoft.com/en/samples/m ... -from-code
Please let us know if you need more details on how to implement that.
Thank you,
Edward
Re: Postback edited Report on button-click
Hello Edward,
Thank you for your answer, but I am afraid you misunderstood my intentions.
I want to display a report like in this sample to my users:
https://www.stimulsoft.com/en/documenta ... itable.htm
But instead of having the user switch to edit mode, edit, than switch back from edit-mode to apply the changes to the report, I want do the following:
• Edit-Mode should already be active when the page is rendered. (No need for the user to click the corresponding button in the viewer-panel)
• I want to display a button (somewhere on the webpage) that the user simply clicks after he has finished editing to apply the changes and post the changed report back to the server.
To put it differently, I want to use the report as a kind of web form that the user can fill in and then post back (changes and all) to the server.
best regards
Scotty
Thank you for your answer, but I am afraid you misunderstood my intentions.
I want to display a report like in this sample to my users:
https://www.stimulsoft.com/en/documenta ... itable.htm
But instead of having the user switch to edit mode, edit, than switch back from edit-mode to apply the changes to the report, I want do the following:
• Edit-Mode should already be active when the page is rendered. (No need for the user to click the corresponding button in the viewer-panel)
• I want to display a button (somewhere on the webpage) that the user simply clicks after he has finished editing to apply the changes and post the changed report back to the server.
To put it differently, I want to use the report as a kind of web form that the user can fill in and then post back (changes and all) to the server.
best regards
Scotty
Re: Postback edited Report on button-click
Hello,
We need some additional time to investigate the possibility to implement it in the Web version.
We will let you know about the result.
Thank you.
We need some additional time to investigate the possibility to implement it in the Web version.
We will let you know about the result.
Thank you.
-
- Posts: 6247
- Joined: Tue Mar 20, 2018 5:34 am
Re: Postback edited Report on button-click
Hello,
Yes, you can hide the viewer panel (only the report will be displayed), and to control the editing mode call the JavaScript function of the viewer below:
You can also use other functions of the viewer to manage the report:
Thank you.
Yes, you can hide the viewer panel (only the report will be displayed), and to control the editing mode call the JavaScript function of the viewer below:
Code: Select all
jsMvcViewer1.SetEditableMode(true); // or 'false'
Code: Select all
// Print
jsMvcViewer1.postPrint("PrintPdf");
jsMvcViewer1.postPrint("PrintWithoutPreview");
jsMvcViewer1.postPrint("PrintWithPreview");
// Zoom
jsMvcViewer1.reportParams.zoom = 50;
jsMvcViewer1.postAction("GetPages");
// Set page
jsMvcViewer1.reportParams.pageNumber = 1;
jsMvcViewer1.postAction("GetPages");
// Export
var exportFormat = "Pdf"; // Document, Xps, Ppt2007, Html, Text, Rtf, Word2007, Excel2007, Csv, Jpeg, Png
var exportSettings = jsMvcViewer1.getDefaultExportSettings(exportFormat);
jsMvcViewer1.postExport(exportFormat, exportSettings);
Re: Postback edited Report on button-click
Hello,
thank you for your help.
I tried what you suggested and it worked fine for the most part. But I still have a problem: After displaying and editing the report
by the user he clicks the custom-button to call the postExport-Method. The report is post back to the server and there saved to a
pdf-file. But in this file, the changes he made to the report are missing in the file created on the server. Only after he clicks
the custom button a second time, the pdf-file is overwritten and the changes appear in the document.
Here is what I did:
In the view I have added the following script to create a custom button that, when clicked, calls the postExport-Method of the viewer:
I have also added the necessary options:
On the server side, I have added a handler to the Controller class:
When, after editing, the custom button is clicked, the ExportReport() method is called on the server. After the first click, the file saved
on the server (“Demo.pdf”) contains none of the changes mode during editing. Only after the button is clicked a second time, the changes are
written to the file.
Of course, I would prefer my changes do be saved the first time a user presses the custom –button.
I suppose I am doing something wrong. Can you give me a hint, what it is I am missing here?
PS: I also want to suppress the local export in the browser. What kind of ActionResult should I return in the ExportReport()-Method to achieve this.
Best regards,
Scotty
thank you for your help.
I tried what you suggested and it worked fine for the most part. But I still have a problem: After displaying and editing the report
by the user he clicks the custom-button to call the postExport-Method. The report is post back to the server and there saved to a
pdf-file. But in this file, the changes he made to the report are missing in the file created on the server. Only after he clicks
the custom button a second time, the pdf-file is overwritten and the changes appear in the document.
Here is what I did:
In the view I have added the following script to create a custom button that, when clicked, calls the postExport-Method of the viewer:
Code: Select all
<script type="text/javascript">
jsMvcViewer.SetEditableMode(true);
var customButton = jsMvcViewer.SmallButton("customButton", "Custom Button", "emptyImage");
customButton.image.src = "https://www.stimulsoft.com/favicon.png";
customButton.action = function ()
{
var exportFormat = "Pdf";
var exportSettings = jsMvcViewer.getDefaultExportSettings(exportFormat);
jsMvcViewer.postExport(exportFormat, exportSettings);
}
var toolbarTable = jsMvcViewer.controls.toolbar.firstChild.firstChild;
var buttonsTable = toolbarTable.rows[0].firstChild.firstChild;
var customButtonCell = buttonsTable.rows[0].insertCell(0);
customButtonCell.appendChild(customButton);
</script>
Code: Select all
@Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions()
{
Actions =
{
GetReport = "GetReport",
ViewerEvent = "ViewerEvent",
ExportReport = "ExportReport",
},
})
Code: Select all
public ActionResult ExportReport()
{
StiReport report = StiMvcViewer.GetReportObject();
StiRequestParams parameters = StiMvcViewer.GetRequestParams();
if (parameters.ExportFormat == StiExportFormat.Pdf)
{
Stimulsoft.Report.Export.StiPdfExportSettings settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
report.ExportDocument(StiExportFormat.Pdf, Server.MapPath("~/Content/Data/Demo.pdf"));
}
return StiMvcViewer.ExportReportResult(report);
}
on the server (“Demo.pdf”) contains none of the changes mode during editing. Only after the button is clicked a second time, the changes are
written to the file.
Of course, I would prefer my changes do be saved the first time a user presses the custom –button.
I suppose I am doing something wrong. Can you give me a hint, what it is I am missing here?
PS: I also want to suppress the local export in the browser. What kind of ActionResult should I return in the ExportReport()-Method to achieve this.
Best regards,
Scotty
-
- Posts: 6247
- Joined: Tue Mar 20, 2018 5:34 am
Re: Postback edited Report on button-click
Hello,
This behavior is correct, since the values of the editable parameters are assigned to the report in the StiMvcViewer.ExportReportResult() method, which you call after the report is exported.
In order to assign parameters to the report itself, use the specified method (it is part of the viewer):
Thank you.
This behavior is correct, since the values of the editable parameters are assigned to the report in the StiMvcViewer.ExportReportResult() method, which you call after the report is exported.
In order to assign parameters to the report itself, use the specified method (it is part of the viewer):
Code: Select all
private static void ApplyEditableFieldsToReport(StiReport report, object parameters)
{
if (parameters == null) return;
try
{
var allPagesParams = (Hashtable)parameters;
foreach (DictionaryEntry pageParams in allPagesParams)
{
int pageIndex = Convert.ToInt32(pageParams.Key);
Hashtable allComponetsParams = (Hashtable)pageParams.Value;
foreach (DictionaryEntry compParamsObject in allComponetsParams)
{
var compIndex = Convert.ToInt32(compParamsObject.Key);
var compParams = (Hashtable)compParamsObject.Value;
if (pageIndex < report.RenderedPages.Count)
{
StiPage page = report.RenderedPages[pageIndex];
if (compIndex < page.Components.Count)
{
StiComponent component = page.Components[compIndex];
if ((string)compParams["type"] == "CheckBox" && component is StiCheckBox)
{
((StiCheckBox)component).CheckedValue = (bool)compParams["checked"] ? "true" : "false";
}
else if ((string)compParams["type"] == "Text" && component is StiText)
{
((StiText)component).Text.Value = (string)compParams["text"];
}
}
}
}
}
}
catch (Exception e)
{
Console.Write(e.Message);
}
}
public ActionResult ExportReport()
{
StiReport report = StiMvcViewer.GetReportObject();
StiRequestParams parameters = StiMvcViewer.GetRequestParams();
if (parameters.ExportFormat == StiExportFormat.Pdf)
{
ApplyEditableFieldsToReport(report, parameters.Interaction.Editable);
Stimulsoft.Report.Export.StiPdfExportSettings settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
report.ExportDocument(StiExportFormat.Pdf, Server.MapPath("~/Content/Data/Demo.pdf"));
return new StiMvcActionResult("{}");
}
return StiMvcViewer.ExportReportResult(report);
}
Re: Postback edited Report on button-click
Hello,
now it works as aspected!
Thank you.
now it works as aspected!
Thank you.
-
- Posts: 6247
- Joined: Tue Mar 20, 2018 5:34 am
Re: Postback edited Report on button-click
Hello
We are always glad to help you!
Please let us know if you need any additional help.
Thank you.
We are always glad to help you!
Please let us know if you need any additional help.
Thank you.