Link to home
Start Free TrialLog in
Avatar of SavindraSingh
SavindraSinghFlag for India

asked on

Dynamic label on ASP Panel not working

Hello Experts,

I have an ASP.NET page with bunch of asp Buttons, asp Textbox, one GridView control and an asp Panel with Modal Popup Extender attached. The panel has a Please wait Modal Popup message to be displayed while the processing of code behind the asp button click event  gets completed.

What I want to achive is the wait panel should show the current item it is processing  out of the list it has got from the asp TextBox.

The code is running without any error but it is not changing the value of the Label placed inside the ASP Panel, during the execution of the code.

Out of all the C# code I am posting only the code related to one button (Ping Status). The Code to change the Label text on ASP Panel lays around the 'for each loop' in below  C# code:

C# Code:
======
  protected void btnPingStatus_Click(object sender, EventArgs e)
    {
        if (PageMaster.CheckErrors())
        {
            if (dgOutput.Rows.Count > 0)
            {
                dgOutput.DataSource = null;
                dgOutput.DataBind();
            }

            string[] ServerList;
            string ServerName;
            string IsAlive = "";
            Out_Table.Columns.Add(new DataColumn("Server Name", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("IP Address", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("FQDN", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("Ping Status", typeof(string)));

            if (txtServerList.TextMode == TextBoxMode.MultiLine)
            {
                if (txtServerList.Text == "")
                {
                    lblError.Text = "Error: No Servers listed!";
                    lblError.Visible = true;
                    return;
                }
                lblError.Text = "";
                lblError.Visible = false;
                ServerList = txtServerList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                int i = ServerList.Length;
                lblProcessItem.Visible = true;
                foreach (string Server in ServerList)
                {
                    lblProcessItem.Text = "Processing Item " + i + " of " + ServerList.Length;
                    ServerName = Server;
                    IsAlive = GetPingStatus(ServerName);
                    DataRow Out_Row = Out_Table.NewRow();
                    if (IsAlive != "Failed")
                    {
                        Out_Row["Server Name"] = ServerHostName;
                        Out_Row["IP Address"] = IP_Addr;
                        Out_Row["FQDN"] = FQDN;
                        Out_Row["Ping Status"] = IsAlive;
                        Out_Table.Rows.Add(Out_Row);
                    }
                    else
                    {
                        Out_Row["Server Name"] = ServerName;
                        Out_Row["IP Address"] = "NA";
                        Out_Row["FQDN"] = FQDN;
                        Out_Row["Ping Status"] = IsAlive;
                        Out_Table.Rows.Add(Out_Row);
                    }
                    i++;
                }
                lblProcessItem.Text = "Done!";
                dgOutput.DataSource = Out_Table;
                dgOutput.DataBind();
                lblProcessItem.Visible = false;
            }
            else
            {
                if (txtServerList.Text == "")
                {
                    lblError.Text = "Error: No Servers listed!";
                    lblError.Visible = true;
                    return;
                }
                lblError.Text = "";
                lblError.Visible = false;
                ServerName = txtServerList.Text;
                IsAlive = GetPingStatus(ServerName);
                DataRow Out_Row = Out_Table.NewRow();
                Out_Row["Server Name"] = ServerHostName; Out_Row["IP Address"] = IP_Addr; Out_Row["FQDN"] = FQDN; Out_Row["Ping Status"] = IsAlive;
                Out_Table.Rows.Add(Out_Row);
                dgOutput.DataSource = Out_Table;
                dgOutput.DataBind();
            }
        }
    }

Open in new window


ASP.NET Code:
==========
<%@ Page Title="Wintel SinglePoint" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="AdministrationPage" ContentPlaceHolderID="AdministrationContent" Runat="Server">
    <script type="text/javascript" language="javascript">
    function pageLoad(sender, args) {
        var sm = Sys.WebForms.PageRequestManager.getInstance();
        if (!sm.get_isInAsyncPostBack()) {
            sm.add_beginRequest(onBeginRequest);
            sm.add_endRequest(onRequestDone);
        }
    }

    function onBeginRequest(sender, args) {
        var send = args.get_postBackElement().value;
        if (displayWait(send) == "yes") {
            $find('pnlWait_ModalPopupExtender').show();
        }
    }

    function onRequestDone() {
        $find('pnlWait_ModalPopupExtender').hide();
    }

    function displayWait(send) {
        switch (send) {
            case "Ping Status":
                return ("yes");
                break;
            case "Service Details":
                return ("yes");
                break;
            case "NIC Details":
                return ("yes");
                break;
            case "Clear Output":
                return ("yes");
                break;
            default:
                return ("no");
                break;
        }
    }
</script>
    <div style="font-family:Arial; font-size:small;">
        <asp:UpdatePanel ID="upMain" runat="server">
            <ContentTemplate>
                <table style="width:100%;">
                    <tr>
                        <td class="columnHeader">
                            Input Servers</td>
                        <td class="columnHeader">
                            Select Service Options</td>
                        <td class="columnHeader">
                            Actions</td>
                    </tr>
                    <tr>
                        <td style="width:270px">
                            <asp:RadioButton ID="rbSingleServer" runat="server" GroupName="ListType" 
                            oncheckedchanged="rbSingleServer_CheckedChanged" Text="Single Server"
                            AutoPostBack="True" CausesValidation="True" />
                                    &nbsp;
                            <asp:RadioButton ID="rbMultipleServers" runat="server" GroupName="ListType" 
                            oncheckedchanged="rbMultipleServers_CheckedChanged" Text="Multiple Servers" 
                            AutoPostBack="True" CausesValidation="True" />
                        </td>
                        <td style="width:380px;">
                            <center>
                            <asp:RadioButton ID="rbServiceName" runat="server" AutoPostBack="True" 
                                CausesValidation="True" GroupName="SrvCriteria" 
                                oncheckedchanged="rbServiceName_CheckedChanged" Text="By Service Name" />
                            &nbsp;<b>OR</b>
                            <asp:RadioButton ID="rbAllServices" runat="server" AutoPostBack="True" 
                                CausesValidation="True" GroupName="SrvCriteria" 
                                oncheckedchanged="rbAllServices_CheckedChanged" Text="All Services" />
                            </center>
                        </td>
                        <td style="width:80px;">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width:270px; text-align:center; vertical-align:top;">
                            <asp:Label ID="lblServerList" runat="server" Text="Enter Server Name">
                            </asp:Label>
                            <br />
                            <asp:TextBox ID="txtServerList" runat="server" Width="295px" 
                                ToolTip="Add multiple servers seperated by new line"></asp:TextBox>
                        </td>
                        <asp:RequiredFieldValidator ID="rfvServername"
                             runat="server"
                             ErrorMessage="Server name is required"
                             ControlToValidate="txtServerList"
                             Display="None"
                             ValidationGroup="vgServername"
                             EnableClientScript="false">
                        </asp:RequiredFieldValidator>
                        <td style="text-align: center; vertical-align:top; width:380px;">
                            <br />
                            <asp:CheckBox ID="chkMultiServices" runat="server" AutoPostBack="True" 
                                CausesValidation="True" oncheckedchanged="chkMultiServices_CheckedChanged" 
                                Text="Check Multiple Services" 
                                ToolTip="Put multiple services on new line" />
                            &nbsp;(For Multiple Services seperate by new line)<br /> Service Name(s):&nbsp;&nbsp;<asp:TextBox 
                                ID="txtServiceName" runat="server" ToolTip="Put multiple services on new line" 
                                Width="184px"></asp:TextBox>
                            &nbsp;</td>
                        <td style="text-align:center; vertical-align:top;">
                            <br />
                            <asp:Button ID="btnPingStatus" runat="server" onclick="btnPingStatus_Click" 
                                Text="Ping Status" ToolTip="Check if server gives a response for ping" 
                                Width="130px" />
                            <br />
                            <br />
                            <asp:Button ID="btnGetServiceDetails" runat="server" 
                                onclick="btnGetServiceDetails_Click" Text="Service Details" />
                            <br />
                            <br />
                            <asp:Button ID="btnGetNICDetails" runat="server" 
                                onclick="btnGetNICDetails_Click" Text="NIC Details" 
                                ToolTip="Get DNS, WINS, MAC Address and other details of the NICs" 
                                Width="130px" />
                            <br />
                            <br />
                            <asp:Button ID="btnClearOutput" runat="server" onclick="btnClearOutput_Click" 
                                Text="Clear Output" Width="130px" />
                        </td>
                    </tr>

                    <tr>
                        <td colspan="3" 
                            
                            style="text-align: center; font-weight: 700; border-bottom: 1px solid Black">
                            <asp:Label ID="lblError" runat="server" Text="Error:" 
                                style="font-family:Arial; color:Red; font-weight:bold;" BackColor="Black" 
                                BorderColor="#0000CC" BorderStyle="Solid" BorderWidth="1px" Visible="False"></asp:Label>
                            <br />
                            OUTPUT DETAILS</td>
                    </tr>

                    <tr>
                        <td colspan="3">
                            <center>
                                <asp:GridView ID="dgOutput" runat="server" BackColor="White" 
                                    BorderColor="#006699" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                                    GridLines="Both">
                                    <AlternatingRowStyle BackColor="#B8DCDB" />
                                    <FooterStyle BackColor="#B8CFDC" ForeColor="#4A3C8C" />
                                    <HeaderStyle BackColor="#246193" Font-Bold="True" ForeColor="#F7F7F7" />
                                    <PagerStyle BackColor="#E7E7FF" ForeColor="#003366" HorizontalAlign="Right" />
                                    <RowStyle BackColor="#D8EBFE" ForeColor="#003366" />
                                    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                                    <SortedAscendingCellStyle BackColor="#F4F4FD" />
                                    <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                                    <SortedDescendingCellStyle BackColor="#D8D8F0" />
                                    <SortedDescendingHeaderStyle BackColor="#3E3277" />
                                </asp:GridView>
                            </center>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <center>
            <asp:Panel ID="pnlWait" runat="server" Width="230px"
                style="border-color:Gray; border-bottom-width:thick; border-style:solid; text-align:center; display:none;">
                    <div class="h3">
                        Please wait...<br />
                        <img alt="Please wait..." style="width:35%; height:50%;" 
                            src="App_Themes/Images/Processing.gif" />
                        <br />
                        <asp:Label ID="lblProcessingRequest" runat="server" 
                            Text="Processing your request"></asp:Label>
                        &nbsp;<br />
                        <asp:Label ID="lblProcessItem" runat="server" ForeColor="#0000CC" 
                            Text="Processing Items"></asp:Label>
                        <br /> 
                    </div>
            </asp:Panel>
                    <asp:Button ID="HiddenButton" runat="server" CssClass="hidden" Text="HiddenButton" />
            <asp:ModalPopupExtender 
                    ID="pnlWait_ModalPopupExtender"
                    runat="server" 
                    Enabled="True"
                    BehaviorID="pnlWait_ModalPopupExtender"
                    TargetControlID="HiddenButton"
                    PopupControlID="pnlWait"
                    BackgroundCssClass="modalBackground" DynamicServicePath="">
            </asp:ModalPopupExtender>
        </center>
    <br />
    </div>
</asp:Content>

Open in new window

Avatar of hes
hes
Flag of United States of America image

Try adding
Application.DoEvents();

before and after your label

Application.DoEvents();
lblProcessItem.Text = "Processing Item " + i + " of " + ServerList.Length;
Application.DoEvents();



Avatar of SavindraSingh

ASKER

Thanks for your response:

FYI,

The code is written under C# and Application doesnot support/have any method called DoEvents()

Hence when I add above line before and after the lable; DoEvents is being underlined in Red Color.

Regards,
Savindra
Namespace:  System.Windows.Forms
using System.Windows.Forms;
Thanks for your reply. This project is on m office computer. I do not have Visual Studio on my home computer. I will try this on Monday when I will reach office and reply back with update.
No problem
Thanks Hes,

I tried this solution but it didn't work :-(
Any other suggestions?

    protected void btnPingStatus_Click(object sender, EventArgs e)
    {
        if (PageMaster.CheckErrors())
        {
            if (dgOutput.Rows.Count > 0)
            {
                dgOutput.DataSource = null;
                dgOutput.DataBind();
            }

            string[] ServerList;
            string ServerName;
            string IsAlive = "";
            Out_Table.Columns.Add(new DataColumn("Server Name", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("IP Address", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("FQDN", typeof(string)));
            Out_Table.Columns.Add(new DataColumn("Ping Status", typeof(string)));

            if (txtServerList.TextMode == TextBoxMode.MultiLine)
            {
                if (txtServerList.Text == "")
                {
                    lblError.Text = "Error: No Servers listed!";
                    lblError.Visible = true;
                    return;
                }
                lblError.Text = "";
                lblError.Visible = false;
                ServerList = txtServerList.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                int i = ServerList.Length;
                lblProcessItem.Visible = true;
                foreach (string Server in ServerList)
                {
                    System.Windows.Forms.Application.DoEvents();
                    lblProcessItem.Text = "Processing Item " + i + " of " + ServerList.Length;
                    System.Windows.Forms.Application.DoEvents();
                    ServerName = Server;
                    IsAlive = GetPingStatus(ServerName);
                    DataRow Out_Row = Out_Table.NewRow();
                    if (IsAlive != "Failed")
                    {
                        Out_Row["Server Name"] = ServerHostName;
                        Out_Row["IP Address"] = IP_Addr;
                        Out_Row["FQDN"] = FQDN;
                        Out_Row["Ping Status"] = IsAlive;
                        Out_Table.Rows.Add(Out_Row);
                    }
                    else
                    {
                        Out_Row["Server Name"] = ServerName;
                        Out_Row["IP Address"] = "NA";
                        Out_Row["FQDN"] = FQDN;
                        Out_Row["Ping Status"] = IsAlive;
                        Out_Table.Rows.Add(Out_Row);
                    }
                    i++;
                }
                lblProcessItem.Text = "Done!";
                dgOutput.DataSource = Out_Table;
                dgOutput.DataBind();
                lblProcessItem.Visible = false;
            }
            else
            {
                if (txtServerList.Text == "")
                {
                    lblError.Text = "Error: No Servers listed!";
                    lblError.Visible = true;
                    return;
                }
                lblError.Text = "";
                lblError.Visible = false;
                ServerName = txtServerList.Text;
                IsAlive = GetPingStatus(ServerName);
                DataRow Out_Row = Out_Table.NewRow();
                Out_Row["Server Name"] = ServerHostName; Out_Row["IP Address"] = IP_Addr; Out_Row["FQDN"] = FQDN; Out_Row["Ping Status"] = IsAlive;
                Out_Table.Rows.Add(Out_Row);
                dgOutput.DataSource = Out_Table;
                dgOutput.DataBind();
            }
        }
    }

Open in new window

Just to make the picture more clear:

This page (default.aspx) is having another page Masterpage.master as master page.

If you observe the ASP.NET Code I provided above you will find that the Label which should get updated with above C# code is placed on a ASP Panel (ID=pnlWait) that has pne ModalPopupExtender attached to it. And the button which is triggering the display of this "Please wait" modal popup is placed on an ASP UpdatePanel on default.aspx.

Does, placing these contols on different panels and pages is causing this to fail? Just a doubt.
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your inputs. It seems I have reached a ded-end :-(

Though, I will scrutinize these links and will get back to you soon.
These links are found really helpful. But it is sad to know that what I was trying to do can't be achived in ASP.NET