0

我正在尝试提供一个确定取消弹出窗口“如果”gridview 没有行,并且我认为这将像客户端脚本一样工作,但是当我点击确定时,控件会跳过该方法的其余部分。无论如何我可以执行此验证或警报并将控件移动到下一条语句吗?

protected void btnRunD_Click(object sender, EventArgs e)
 {
       try
        {
            int iESStatus = 0;
            int iRunStatus = 0;
            ApplicationUser au = (ApplicationUser)Session["ApplicationUser"];
            if (UploadFileGrid.Rows.Count <= 0)
            {
               ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),     "err_msg", "confirm('No new data files have been uploaded. Are you sure you want to run EYDS Processing Module?');",
           //true);
            }

            if (au.RoleID != 2) //RoleID is not Admin!
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('You do not have enough privileges to use this functionality!');",
           true);
           }
           else
           {.........}
}

我遇到困难的部分在这里:
我正在尝试提供一个好的取消弹出窗口'如果'gridview没有行

if (UploadFileGrid.Rows.Count <= 0)
    {
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "confirm('No new data files have been uploaded. Are you sure you want to run?');",       
    }
4

2 回答 2

3

假设您的按钮是这样的:

<asp:Button ID="btnDoSomething" runat="server" Text="Do Something" OnClientClick="return GetConfirmation();"  OnClick="btnDoSomething_Click" />

然后添加一个javascript函数如下:

function GetConfirmation() {
    var rowscount = document.getElementByID(<%=UploadFileGrid.ClientID%>).rows.length;
    return rowscount > 0 || confirm('No new data files have been uploaded. Are you sure you want to run?');
}

然后它会在显示确认按钮时用户按下 ok 时被回发。

于 2012-09-18T05:55:40.137 回答
1

您可以使用 javascript 或 jquery 来完成:

$("#<%=btnApprove.ClientID %>").click(function () {
            if ($("#<%=UploadFileGrid.ClientID %> ").find("tr").length == 0) {
                if (confirm('No new data files have been uploaded. Are you sure you want to run?')) {
                    return true;
                }
                else {
                    return false;
                }
            }

        });

当用户按下确定时,您的页面将被回发,您可以编写您想要执行的代码。我希望这段代码对你有帮助。

于 2012-09-18T06:10:28.480 回答