One feature in my app is the "export to excel" option. Upon clicking this button, a confirmation message appears for user validation. When the user clicks OK, a JavaScript click event is triggered.
<asp:Content ID="Content3" ContentPlaceHolderID="PagePlaceholder" runat="Server">
<asp:ScriptManager ID="smMainpage" runat="server">
</asp:ScriptManager>
<table style="width: 100%">
<tr>
<td colspan="2">
<asp:UpdatePanel runat="server" ID="up">
<ContentTemplate>
<div style="text-align: left; font-size: 8pt" id="div5" runat="server">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="right" style="width: 50%">
<table>
<tr>
<td style="display: none">
<asp:Button ID="btnblkupdate" runat="server" Text="None" OnClick="btnblkupdate_click" />
<div>
<asp:Button ID="btnhdnExport" runat="server" OnClick="btnhdnExport_click" /></div>
</td>
<td>
<asp:LinkButton ID="lnkExport" OnClick="lnkExport_Click" CssClass="customFont" runat="server"
Text="Export to Excel"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkbtnFilter" OnClick="lnkbtnFilter_Click" CssClass="customFont"
runat="server" Text="Filter Data"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkReset" OnClick="lnkReset_Click" Visible="false" CssClass="customFont"
runat="server" Text="Reset Filter"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkbtnViewAll" OnClick="lnkbtnViewAll_Click" runat="server" Text="View All"></asp:LinkButton>
Selected Records:<asp:Label ID="lblselTsks" Width="20px" Font-Size="10pt"
Font-Bold="true" runat="server" Text="0"></asp:Label>
</td>
<td>
Total Records found: <asp:Label ID="lblTotRecCount" Font-Bold="true" runat="server"
ForeColor="Black" Font-Size="10pt" Text="0"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="lnkExport" />
<asp:PostBackTrigger ControlID="btnhdnExport" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress5" EnableViewState="false" AssociatedUpdatePanelID="up"
DisplayAfter="10" runat="server">
<ProgressTemplate>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
protected void lnkExport_Click(object sender, EventArgs e)
{
DataSet dsResult = new DataSet();
try
{
string strName = string.Empty;
clsSearch_BL clsObj = new clsSearch_BL();
//dsResult = (DataSet)Session["SearchRes"];
if (Session["detObj"] != null)
{
DetState detObj = (DetState)Session["detObj"];
dsResult = clsObj.getSearchResults_BL(detObj);
HashSet<string> orderIdclmtest = new HashSet<string>();
int j = dsResult.Tables[0].Rows.Count;
for (int k = 0; k < j; k++)
{
orderIdclmtest.Add( dsResult.Tables[0].Rows[k][1].ToString());
}
Session["orderIdclmtest"] = orderIdclmtest.ToString();
HashSet<string> strtest = new HashSet<string>();
strtest =(HashSet<string>)Session["orderIdclm"];
var testttt=strtest.Except(orderIdclmtest).ToList();
int cnt = testttt.Count;
StringBuilder str = new StringBuilder();
for (int i = 0; i < cnt; i++)
{
if (str.Length == 0)
str.Append(testttt[i]);
else
str.Append(", " + testttt[i]);
}
ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "export", "hdnExportExcel()", true);
//if (testttt != null && testttt.Any())
//{
// ScriptManager.RegisterClientScriptBlock(this.up, this.GetType(), "export", "hdnExportExcel('"+str+"')", true);
//}
}
}
catch (Exception ex)
{
log4net.Config.XmlConfigurator.Configure();
log.Warn("Logging:" + ex);
}
finally {
if(dsResult != null)
dsResult.Dispose();
}
}
function hdnExportExcel() {
if (confirm('You are about to miss the tasks do you want to continue?')) {
document.getElementById('ctl00_PagePlaceholder_btnhdnExport').click();
}
else {
return false;
}}
I am encountering an issue where
document.getElementById('ctl00_PagePlaceholder_btnhdnExport')
is returning null. Strangely, the element with ID ctl00_PagePlaceholder_btnhdnExport
does exist in the page source.
I suspect that the problem may be related to the postbacktrigger within the updatepanel. I attempted moving the btnhdnExport
outside of the update panel and removed it from triggers, but this did not resolve the issue. Any suggestions would be greatly appreciated.
Thank you in advance