Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
I am using the ASP.NET WebForms framework and embedding the report using a JavaScript SDK approach.
The `powerBIReportContainer` div does not display the report when it is placed inside an `<asp:UpdatePanel>`.
Note: using Wizard forms as well.
When the `powerBIReportContainer` div is positioned outside the `</asp:UpdatePanel>`, the Power BI report renders correctly.
Below is my code snippet. Could you please assist me with what changes I need to make in my JavaScript or any other solutions?
</ContentTemplate>
</asp:UpdatePanel>
<script src="https://cdn.jsdelivr.net/npm/powerbi-client@2.19.0/dist/powerbi.js"></script>
<asp:Button ID="btnGenerateReport" runat="server" Text="Generate Report" CssClass="genric_btn green" OnClick="btnGenerateReport_Click" />
<div id="powerBIReportContainer" style="height:600px;width:100%;"></div>
<script type="text/javascript">
var embedUrl = '<%= EmbedUrl %>';
var embedToken = '<%= EmbedToken %>';
var reportId = '<%= ReportId %>';
function embedPowerBIReport() {
if (!embedUrl || !embedToken || !reportId) return;
var models = window['powerbi-client'].models;
var embedConfig = {
type: 'report',
isPaginatedReport: true,
id: reportId,
embedUrl: embedUrl,
accessToken: embedToken,
tokenType: models.TokenType.Embed,
settings: {
panes: {
filters: { visible: false },
pageNavigation: { visible: true }
},
navContentPaneEnabled: true
}
};
var reportContainer = document.getElementById('powerBIReportContainer');
powerbi.reset(reportContainer);
var report = powerbi.embed(reportContainer, embedConfig);
// Show page navigation after report is loaded
report.on("loaded", function () {
report.updateSettings({
panes: {
pageNavigation: { visible: true }
}
});
});
}
window.onload = function () {
embedPowerBIReport();
};
</script>
</div>
</div>
</asp:Content>
Hey @Lakshmanan1 ,
In your situation, the issue likely arises because the UpdatePanel is performing a partial postback, which can cause the embedded Power BI report to not render properly. The JavaScript code you're using to embed the Power BI report might be running before the UpdatePanel finishes updating its content, causing the report container (#powerBIReportContainer) to not be fully loaded or accessible.
1. Trigger JavaScript After UpdatePanel Completes: The issue can be resolved by ensuring that the Power BI embedding code runs after the UpdatePanel has been updated. You can do this by hooking into the Sys.Application.add_load event, which ensures the Power BI report embedding happens only after the UpdatePanel is fully refreshed.
Update your script to include Sys.Application.add_load like so:
<script type="text/javascript"> var embedUrl = '<%= EmbedUrl %>'; var embedToken = '<%= EmbedToken %>'; var reportId = '<%= ReportId %>'; function embedPowerBIReport() { if (!embedUrl || !embedToken || !reportId) return; var models = window['powerbi-client'].models; var embedConfig = { type: 'report', isPaginatedReport: true, id: reportId, embedUrl: embedUrl, accessToken: embedToken, tokenType: models.TokenType.Embed, settings: { panes: { filters: { visible: false }, pageNavigation: { visible: true } }, navContentPaneEnabled: true } }; var reportContainer = document.getElementById('powerBIReportContainer'); powerbi.reset(reportContainer); var report = powerbi.embed(reportContainer, embedConfig); // Show page navigation after report is loaded report.on("loaded", function () { report.updateSettings({ panes: { pageNavigation: { visible: true } } }); }); } // Trigger embedding after UpdatePanel updates Sys.Application.add_load(function () { embedPowerBIReport(); }); </script>
2. Ensure Button Triggers UpdatePanel: Ensure that the btnGenerateReport button triggers the UpdatePanel refresh when clicked. Make sure the UpdatePanel wraps the content to be updated.
3.Embedding After Postback: Use Sys.Application.add_load to execute the embedding script after the UpdatePanel completes its update during a postback.
For Detailed Information:
Embedding Power BI in Web Applications
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
Thanks for your response.
As you suggested i added Sys.Application.add_load . But still the PowerBI not rendering. FYI. the update panel is on ascx page.
// Trigger embedding after UpdatePanel updates Sys.Application.add_load(function () { embedPowerBIReport(); });
Hey @Lakshmanan1 ,
Since Sys.Application.add_load didn't resolve the issue, here are some other things to try:
Ensure UpdatePanel wraps both the button and the report container to ensure they are updated together.
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="btnGenerateReport" runat="server" Text="Generate Report" /> <div id="powerBIReportContainer" style="height:600px;"></div> </ContentTemplate> </asp:UpdatePanel>
Use PageRequestManager for postback completion:
var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(function () { embedPowerBIReport(); });
Reset the report if already embedded:
var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(function () { powerbi.reset(document.getElementById('powerBIReportContainer')); embedPowerBIReport(); });
Check for any JavaScript errors in the browser's developer tools console.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
Hi Nasif,
I used the code you suggested . But still not working and erros in browser's developer tools console.
Is that anything i am missing.
<asp:UpdatePanel ID="UpdatePanelReport" runat="server">
<ContentTemplate>
<div class="clear"></div>
<div class="search-col3">
<asp:Button ID="btnBack" runat="server" Text="<< Back" OnClick="btnBack_Click" CssClass="genric_btn " Visible="false" />
<%--<asp:Button ID="btnGenerateReport" runat="server" Text="Generate Report" CssClass="genric_btn green" OnClick="btnGenerateReport_Click" />--%>
</div>
<%--<div id="powerBIReportContainer" style="height:600px;width:100%;"></div>--%>
<%--<iframe role="presentation" width="800" height="600" src="https://app.powerbi.com/rdlEmbed?reportId=b223aaaa-4504-4b25-9ac3-bc8cb2ebcbfe&autoAuth=true&ctid=31..." frameborder="0" allowFullScreen="true"></iframe>--%>
<%--<rsweb:ReportViewer ID="UserLoginActivityReportReportViewer" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" KeepSessionAlive="false" AsyncRendering="false" CssClass="ReportHeightWidth" SizeToReportContent="true" ShowPrintButton="false" OnPreRender="ReportViewer_PreRender" Visible="false" ></rsweb:ReportViewer>--%>
<script src="https://cdn.jsdelivr.net/npm/powerbi-client@2.19.0/dist/powerbi.js"></script>
<asp:Button ID="btnGenerateReport" runat="server" Text="Generate Report" OnClick="btnGenerateReport_Click" />
<div id="powerBIReportContainer" style="height:600px;width:100%;"></div>
<script type="text/javascript">
var embedUrl = '<%= EmbedUrl %>';
var embedToken = '<%= EmbedToken %>';
var reportId = '<%= ReportId %>';
function embedPowerBIReport() {
if (!embedUrl || !embedToken || !reportId) return;
var models = window['powerbi-client'].models;
var embedConfig = {
type: 'report',
isPaginatedReport: true,
id: reportId,
embedUrl: embedUrl,
accessToken: embedToken,
tokenType: models.TokenType.Embed,
settings: {
panes: {
filters: { expanded: false, visible: false },
pageNavigation: { visible: true },
parameters: { expanded: false, visible: false }// Hides the parameter pane }
},
navContentPaneEnabled: true
}
};
var reportContainer = document.getElementById('powerBIReportContainer');
powerbi.reset(reportContainer);
var report = powerbi.embed(reportContainer, embedConfig);
report.on("loaded", function () {
report.updateSettings({
panes: {
filters: { expanded: false, visible: false },
pageNavigation: { visible: true },
parameters: { expanded: false, visible: false }
}
});
});
}
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(function () {
powerbi.reset(document.getElementById('powerBIReportContainer'));
embedPowerBIReport();
});
</script>
</ContentTemplate>
</asp:UpdatePanel>
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
6 | |
4 | |
3 | |
3 | |
2 |