我的应用程序中有一个“导出到 excel”选项。当我单击该按钮时,我正在向用户显示一条确认消息。当用户单击确定时,我正在使用 JavaScript 调用单击事件。
<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;
}}
我的问题是我得到document.getElementById('ctl00_PagePlaceholder_btnhdnExport')
的是空的。但在页面的源代码中,我可以看到元素 ID 为ctl00_PagePlaceholder_btnhdnExport
我不知道为什么它不起作用。我猜这是因为更新面板中的回发触发器。我尝试放置btnhdnExport
外部更新面板并将其从触发器选项中删除。但它没有用。有什么建议么?
提前致谢