Solved

Dynamic label on ASP Panel not working

Posted on 2011-03-18
12
498 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:SavindraSingh
  • 6
  • 4
12 Comments
 
LVL 20

Expert Comment

by:hes
ID: 35165350
Try adding
Application.DoEvents();

before and after your label

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



0
 
LVL 5

Author Comment

by:SavindraSingh
ID: 35165453
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
0
 
LVL 20

Expert Comment

by:hes
ID: 35165664
Namespace:  System.Windows.Forms
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 20

Expert Comment

by:hes
ID: 35165677
using System.Windows.Forms;
0
 
LVL 5

Author Comment

by:SavindraSingh
ID: 35171389
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.
0
 
LVL 20

Expert Comment

by:hes
ID: 35172382
No problem
0
 
LVL 5

Author Comment

by:SavindraSingh
ID: 35178647
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

0
 
LVL 5

Author Comment

by:SavindraSingh
ID: 35178669
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.
0
 
LVL 30

Accepted Solution

by:
MlandaT earned 500 total points
ID: 35238752
What you are trying to do does not work in ASP.NET. The model for ASP.NET web applications does not allow for intermediate states of you label control to be communicated back to the user's browser. Only the FINAL state of the label will be returned. If you want to show intermediate states of the label, you will have to come up with your own custom scheme for progress updates which relies on some form of AJAX processing. Typically the actaul solution is actaully quite complex for achieving what is seemingly a simple objective.

Have a look at:

http://msdn.microsoft.com/en-us/magazine/cc163553.aspx
http://aspdotnetmatters.blogspot.com/2010/08/aspnet-handling-long-running-process-in.html
http://www.aspfree.com/index2.php?option=content&task=view&id=2384&pop=1&hide_ads=1&page=0&hide_js=1

Hope this helps. But the key is to appreciate that web forms are "totally" (well... sort of) different from windows forms.
0
 
LVL 5

Author Comment

by:SavindraSingh
ID: 35243339
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.
0
 
LVL 5

Author Closing Comment

by:SavindraSingh
ID: 35251795
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question