按钮单击事件未在ASP.NET的更新面板中触发

时间:2016-02-22 08:07:51

标签: c# asp.net updatepanel

当我点击第一个按钮时,我在更新面板中有两个按钮,然后回发正常工作但是当我点击另一个按钮时,回发根本不会发生。 我得到了java脚本错误。 此外,我不想使用AutoPostback Trigger.And不能在更新面板外保留按钮。 错误消息

错误:Sys.WebForms.PageRequestManagerServerErrorException:在服务器上处理请求时发生未知错误。从服务器返回的状态代码是:401

ASPX代码:

<asp:ScriptManager ID="scriptmanager" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="upMFHoldings" runat="server">
    <ContentTemplate>
        <div id="divConditional" runat="server" class="row " style="margin-left: 5%; margin-bottom: 0.5%;
            margin-right: 5%; padding-bottom: 0.5%;">
      <div class="col-md-12 col-xs-12 col-sm-12" style="margin-bottom: 1%">
                <div class="col-md-1" style="text-align: right; padding-top: 3px">
                    Account
                </div>
                <div class="col-md-3">
                    <asp:DropDownList ID="ddlPortfolio" runat="server" CssClass="form-control input-sm">
                    </asp:DropDownList>
                </div>
                <div class="col-md-3">
                    <asp:Button ID="btnUnitHolding" runat="server" Text="GO" CssClass="btn btn-primary btn-primary"
                        OnClick="btnUnitHolding_Click" />
                    <asp:Label ID="lblPickDate" Text="" runat="server" CssClass="FieldName" Visible="false"> </asp:Label>
                </div>
                <div style="float: right">
                    <asp:ImageButton Visible="false" ID="btnExport" ImageUrl="~/App_Themes/Maroon/Images/Export_Excel.png"
                        runat="server" AlternateText="Excel" ToolTip="Export To Excel" OnClick="btnExportFilteredData_OnClick"
                       Height="25px" Width="29px"></asp:ImageButton>
                </div>
            </div>
 <div id="Div1" class="row" style="margin-left: 5%; margin-right: 3%; background-color: #2480C7;"
            visible="false" runat="server">
            <telerik:RadGrid ID="rgUnitHolding" runat="server" GridLines="None" AllowPaging="True"
                PageSize="3" AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="true"
                AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"
                HorizontalAlign="NotSet" CellPadding="15" OnNeedDataSource="rgUnitHolding_OnNeedDataSource"
                OnItemCommand="rgUnitHolding_OnItemCommand" OnItemDataBound="rgUnitHolding_ItemDataBound">
                <MasterTableView CommandItemDisplay="None" DataKeyNames="MFNPId,AccountId,AMCCode,SchemeCode"
                    AllowCustomSorting="true">
                    <Columns>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
 <%-- Some Grid Columns are there --%>
   </ItemTemplate>
                        </telerik:GridTemplateColumn>
    </Columns>
                </MasterTableView>
  </telerik:RadGrid>
        </div>
      <asp:HiddenField ID="hdnAccount" runat="server" Value="0" />
    </ContentTemplate>
    <Triggers>

    </Triggers>
</asp:UpdatePanel>

代码背后:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using WealthERP.Base;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Globalization;
using System.Drawing;
using System.Diagnostics;
using Excel = Microsoft.Office.Interop.Excel;
using System.Net;
namespace WealthERP.OnlineOrderManagement
{
    public partial class CustomerMFUnitHoldingList : System.Web.UI.UserControl
    {
 protected void Page_Load(object sender, EventArgs e)
        {

}
protected void BindUnitHolding()
        {
            DataTable dt = new DataTable();

            OnlineMFHoldingList = customerPortfolioBo.GetOnlineUnitHolding(customerId, int.Parse(hdnAccount.Value));
            if (OnlineMFHoldingList != null)
            {
 rgUnitHolding.DataSource = dt ;
                    rgUnitHolding.DataBind();

}
}
 protected void btnExportFilteredData_OnClick(object sender, EventArgs e)
        {

            DataTable dtUnitHolding = new DataTable();
            dtUnitHolding = (DataTable)Cache["UnitHolding" + userVo.UserId.ToString()];
            System.Data.DataView view = new System.Data.DataView(dtUnitHolding);
            System.Data.DataTable selected =
                    view.ToTable("Selected", false, "Scheme", "FolioNum", "PurchasedUnits", "InvestedCost", "NAV", "Unrealised Gain/Loss", "CurrentValue", "UnitsSold", "Sold Value", "Realised Gain/Loss");
            if (selected.Rows.Count > 0)
            {

                string data = null;
                int i = 0;
                int j = 0;

                Excel.Workbook xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object misValue = System.Reflection.Missing.Value;

                Excel.Application xlApp = new Excel.Application();
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                int z = 0;
                foreach (DataColumn dtcol in selected.Columns)
                {

                    data = dtcol.ColumnName;
                    xlWorkSheet.Cells[1, z + 1] = data; z++;
                }

                for (i = 1; i <= selected.Rows.Count; i++)
                {
                    for (j = 0; j <= selected.Columns.Count - 1; j++)
                    {
                        data = selected.Rows[i - 1].ItemArray[j].ToString();
                        xlWorkSheet.Cells[i + 1, j + 1] = data;
                    }
                }
                Random asa = new Random();
                string filename = "CustomerHolding" + asa.Next() + ".xls";
                xlWorkBook.SaveAs(Server.MapPath("~/UploadFiles/"+ filename), Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscriptvwewv", "setFormat('" + filename + "');", true);
            }


        }
 protected void btnUnitHolding_Click(object sender, EventArgs e)
        {

            BindUnitHolding();

        }
}
}

这里btnExportFilteredData_OnClick是右键的点击事件

感谢 enter image description here

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我有类似的问题。我将Updatepanel中的UpdateMode属性设置为“Conditional”,然后添加了正确的触发器

https