Page 1 of 1

DocuVieware not working inside ASP Update Panel

Posted: Wed May 16, 2018 11:56 pm
by AJ1985
Hello,

I have simple treeview which displays the documents and when clicked on the node will display the document in DocuVieware. This code works if the treeview and docuvieware are not in the update panel(I have commented the code for update panel and the code works as expected), but if they are inside the update panel the docuvieware is not displaying the document not it is loading the docuvieware control.

Please help me if you know the solution for this issue.

Below is my code:

ASPX Page:
<form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<%-- <asp:UpdatePanel runat="server" ID="up">
<ContentTemplate>--%>

<asp:TreeView runat="server" ID="TreeView1" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
</asp:TreeView>

<cc1:DocuVieware ID="DocuVieware1" runat="server" Height="600px" Width="100%" />

<%--</ContentTemplate>
</asp:UpdatePanel>--%>
</form>

Code behind:
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
var docbyte = from l in db.DocumentRepositories
where l.DocumentRepositoryId == Convert.ToInt32(this.TreeView1.SelectedNode.Value)
select l;
if (docbyte.Any())
{
FileStream stream = new FileStream(docbyte.First().FileLocationPath, FileMode.Open, FileAccess.Read);
DocuVieware1.LoadFromStream(stream, true, this.TreeView1.SelectedNode.Text);
}
}

Re: DocuVieware not working inside ASP Update Panel

Posted: Thu May 24, 2018 9:35 pm
by Loïc
For information here the answer provided by our support staff:
Hello Ajay,

Thank you for the updated project, I've been able to reproduce the issue you described and I've also been able to investigate further.

It turns out it actually works but the DocuVieware auto-generated initialization script does not run on its own in an update panel update postback.
When a DocuVieware control is embedded in a page it will generate its own initialization script called "loadControllerDocuVieware1" when named DocuVieware1 and run it when page is loaded.
This is due to how JavaScript behaves with this asynchronous panel loading page flow, the page load event isn't fired and that's why the control disappears (it is hidden until initialized).
I've been able to work around this issue to fix the problem quite easily though, it is just a matter of telling the update panel to take care of the DocuVieware initialization too.

Basically all you need to do is add a bit of JavaScript in your page to catch the end async postback event and force the initialization script to run at that time.
This is done using Sys.WebForms.PageRequestManager class that raises client events specific to asynchronous postbacks (because there is a ScriptManager control in the form).
So you can do something like this:

Sys.Application.add_init(function () {
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(function () {
loadControllerDocuVieware1();
});
});

This will make sure the self initialization script is properly executed and everything should work as expected.
You will find attached the Default.aspx modified file I have made for reference.

Regards,
Cedric
GdPicture Team

Re: DocuVieware not working inside ASP Update Panel

Posted: Mon Feb 10, 2020 12:35 pm
by mahmoud
Hello Cedric,

I tried this solution and it is not working, the script always stops on the loadControllerDocuVieware1() method because it is not found.
Is there another solution for this problem?

Best Regards,
Mahmoud

Re: DocuVieware not working inside ASP Update Panel

Posted: Thu Feb 13, 2020 7:33 pm
by Loïc
Hi,

I can confirm that the solution provided by Cédric is perfectly working. Here the source code of a POC:

Code: Select all

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="annotations_demo.aspx.cs" Inherits="DocuVieware_webform_app_demo.AnnotationsDemo" %>

<%@ Register Assembly="GdPicture.NET.14.WEB.DocuVieware" Namespace="GdPicture14.WEB" TagPrefix="cc1" %>

<!DOCTYPE html>

<html>
<head>
    <title>DocuVieware - Annotations Demo.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link href="favicon.ico" rel="icon" />
    <link rel="stylesheet" href="style/annotations.css" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel runat="server">
     <ContentTemplate>
          <asp:button runat="server" onclick="ClickButton"/>
                 <cc1:DocuVieware ID="DocuVieware1" runat="server"
            Height="100%"
            Width="100%"
            />
     </ContentTemplate>
</asp:UpdatePanel>


    </form>
    <script>

        Sys.Application.add_init(function () {
            var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
            pageRequestManager.add_endRequest(function () {
                loadControllerDocuVieware1();
            });
        });
    </script>
</body>
</html>

Re: DocuVieware not working inside ASP Update Panel

Posted: Mon Mar 02, 2020 12:54 am
by mahmoud
Hi,

I found my mistake, the provided code works perfectly.

Thanks

Re: DocuVieware not working inside ASP Update Panel

Posted: Tue Apr 07, 2020 8:55 pm
by Loïc
I think our latest version is now automatically handling the complete life cycle of the update-panel without requiring additional coding.

Best regards,

Loïc