开发者

Avoid Page hangup after Registerstartup script firing

开发者 https://www.devze.com 2023-04-03 09:12 出处:网络
I have an asp.net 3.5 application which contains gridview, having checkbox as one of the column. If user doesn\'t select any checkboxes and clicks submit button, alert is firing prompting user to sel

I have an asp.net 3.5 application which contains gridview, having checkbox as one of the column.

If user doesn't select any checkboxes and clicks submit button, alert is firing prompting user to select the button.

The code to fire the alert is as below;

 System.Text.StringBuilder sb = new System.Text.StringBuilder();
 sb.Append(@"<script language='javascript'>");
 sb.Append(@"alert('Please selec开发者_JAVA百科t at least one record!')");
 sb.Append(@"</script>");
 ScriptManager.RegisterStartupScript(upnlGrid, this.GetType(), "GridView", sb.ToString(), false);
 BindGrid();

Until the alert gets fired, i see "Loading..." image (ajax update progress bar), which is fine. But then after the alert gets fired i still need to see the same image, which is not visible. due to which the page gets hangedup for some seconds (5-10 seconds). For that 5-10 seconds i need to show the Loading Image.

Please guide!


You could try validating the selection before doing the postback. Here's a rough example:

<asp:Button ID="Button1" runat="server" Text="Foo" OnClientClick="return validateGridSelection()" ... />

And your JavaScript function:

validateGridSelection = function() {
    var itemsSelected = 0;
    $("#<%=GridView1.ClientID%>").find("input:checkbox").each(function() {
        if (this.checked) {
            itemsSelected++;
        }
    });
    if (itemsSelected == 0) {
        alert("Please select at least one checkbox.");
    }
    return true;
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号