Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

How determine which vb asp.net 4.0 control caused postback?

I am new to vb asp.net development and am writing a web site application.  I need to find out which asp control "button" is causing a postback to the server so I can handle each button differently.

Can someone show me in Visual Basic.net (not C) how to get the button ID or name that caused the postback?

Thanks for the help

Attached is some code I am using but I can't get it to work.  Would appreciate any approach in VB.
Public postbackControlInstance As Control

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        Else
            If Trim(Page.Request.Params.Get("__EVENTTARGET")) = "" Then
                For Me.mI = 0 To Page.Request.Form.Keys.Count
                    postbackControlInstance = Page.FindControl(Page.Request.Form.Keys(Me.mI))

                    'GetUserControlPostBackControl(postbackControlInstance)  (this does not work)

                Next
            End If
    End Sub

    Public Function GetUserControlPostBackControl(ByVal uc As UserControl) As Control
        Dim control As Control = Nothing
        Dim pg As Page = uc.Page
        Dim ctrlname As String = pg.Request.Params("__EVENTTARGET")
        If (Not ctrlname Is Nothing And ctrlname <> String.Empty) Then
            ctrlname = ctrlname.Replace(uc.ID & ":", "")
            control = uc.FindControl(ctrlname)
            ' if __EVENTTARGET is null, the control is a button type and we need to 
            ' iterate over the form collection to find it
        Else
            Dim ctrlStr As String = String.Empty
            Dim c As Control = Nothing
            For Each ctl As String In pg.Request.Form
                'handle ImageButton controls ...
                If (ctl.EndsWith(".x") Or ctl.EndsWith(".y")) Then
                    ctrlStr = ctl.Substring(0, ctl.Length - 2)
                    ctrlStr = ctrlStr.Replace(uc.ID & ":", "")
                    c = uc.FindControl(ctrlStr)
                Else
                    ctl = ctl.Replace(uc.ID & ":", "")
                    c = uc.FindControl(ctl)
                End If
                If TypeOf c Is System.Web.UI.WebControls.Button Or TypeOf c Is System.Web.UI.WebControls.ImageButton Then
                    control = c
                    Exit For
                End If
            Next
        End If
        Return control
    End Function

Open in new window

Avatar of manishkungwani
manishkungwani

The most straightforward way would be write an EventHandler for the Click event from the button in the .aspx.vb file.

The easiest steps:
In the design, double click on the button for which you want to write the code.
This will generate a function definition which will have the necessary parameters and return type.
In this function, write the VB code to do THE TASK that you want to do on that button click.

That's it.
More information is available at:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.click.aspx
Avatar of EYoung

ASKER

I already have a Click event handler for the button.  The problem is that the postback occurs before the click event gets control.
Avatar of EYoung

ASKER

Here is more background:

I have several AJAX buttons on the vb asp.net 4.0 web site page.  When each of the buttons is clicked, I want to make a certain label visible that describes the action taking place.  However, when a button is clicked, apparently a postback occurs first then the click event for the specific button fires.  At that point it is too late to make the associated label visible.

Making the associated label visible on the page I think needs to occur on the server side so that the page will be shown with the visible label.

At least that is my understanding of how button click events and postbacks work.
The event Handling is done this way:

1. You click
2. PageLoad is called
3. Click event handler is called.

so anyways if you do the handling in PageLoad or the ClickHandler, the result will be the same!
Avatar of EYoung

ASKER

But in the PageLoad event how can I know which label to make visible?  I have multiple buttons and each has an associated label and I only want to make the one associated label visible - the one that is associated with the clicked button.  Remember, the user can click one of several buttons and I only want the label associated with the clicked button to be made visible.
Avatar of EYoung

ASKER

After I click the Button4, the PageLoad is called, then the Click event for Button4 is called.  It is my understanding that once the Click event is called the page is already re-rendered on the screen and it would thus be too late to set Button4's label4.visible = true.
Avatar of EYoung

ASKER

And because it is too late to set Label4.visible = True in the click event, that is why the PageLoad event needs to be used.  The problem is that in the PageLoad event, I don't know which button caused the PostBack.

Is my understanding of the event sequences correct?
Yes, it is ALMOST correct :)

If you are not using AJAX for the button click, you can set the visible property in the click and the Page rendering completes after the click event handler finishes execution.
More details: http://msdn.microsoft.com/en-us/library/ms178472.aspx

Assuming that you are using AJAX.
But the PageLoad will not be called when using AJAX and if the button is in an UpdatePanel.

This solution is for ASP.NET AJAX controls:
1. Now, if the button and the Label both are in the same UpdatePanel, you can set the VISIBLE property in the click handler and it will work :)
2. If they are in different UpdatePanels, set the VISIBLE property of the label in the click eventhandler and then call the trigger holding the Label.

and this will set the visible property for only the Label associated with the button :)
So it is NOT too late to Label4.visible = True in the click event.
Avatar of EYoung

ASKER

Thank you for the explanations.

I have been using some AJAX controls including the AJAX ScriptManager and the AjaxControlToolkit.  The Standard asp:button (btnSummary_Start) and the Standard asp:label (Label19) are on the same AJAX asp:UpdatePanel, the same AJAX TabContainer, the same asp:TabPanel, and the same Standard asp:Panel.  (I am using a mixture of AJAX and ASP Standard controls.)

So from what you are saying, if I set label19.visible = true in the button's click event, then the label should show.  I have done that and it does not show.

I put this line at the top of the click event section:  Label19.Visible = True

All of the code in the click event except the "Label19.Visible = True" executes and when done, Label19 becomes visible.  So the click event seems to turn the label's visibility on when the click event code completes and not before.  I want the label19 to be visible prior to the click event code executing in order to let the user know that something is happening.  Once the click event process is done, I want to set label19.visible = false.

I think we are close to solving this.  Attached is part of the aspx.vb code followed by part of the aspx code.

Thank you for sticking with me on this.
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Imports System.DirectoryServices.AccountManagement
Imports System.Web.SessionState.SessionStateItemCollection
Imports System.Diagnostics
Imports Microsoft.Reporting.WebForms

Public NotInheritable Class SessionStateItemCollection
    Inherits NameObjectCollectionBase
    Implements ICollection, IEnumerable
End Class

Partial Class _Default
    Inherits System.Web.UI.Page

    Public mKey As String
    Public mWork_String1 As String
    Public mI As Integer
    Public mEmailAddress As String
    Public mSelectString As DataSourceSelectArguments

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            pnlSummary_Automatic.Visible = True
            srGet_Summary_RunDailyAt()
            txtSummary_ManualDate.Text = FormatDateTime(DateAdd("d", -1, Today), DateFormat.ShortDate)

            pnlDetail_Automatic.Visible = True
            srGet_Detail_RunDailyAt()
            txtDetail_ManualDate.Text = FormatDateTime(DateAdd("d", -1, Today), DateFormat.ShortDate)

            Session("Summary_Report_Started") = "False"
        Else
            btnSummary_Delete.Attributes.Add("onclick", "return confirm('Are you sure you want to DELETE this summary record?');")
            btnDetail_Delete.Attributes.Add("onclick", "return confirm('Are you sure you want to DELETE this detail record?');")
        End If
    End Sub


...



    Protected Sub btnSummary_Start_Click(sender As Object, e As System.EventArgs) Handles btnSummary_Start.Click
        Label19.Visible = True       '<--------   here is the line that turns visibility on

        'First, prepare the Retail_Flash_Detail table 
        Dim targetDir As String
        Dim p As New Process
        targetDir = ("\\tta-cwdw\Apps")
        p.StartInfo.WorkingDirectory = targetDir
        p.StartInfo.FileName = "Retail_Flash_Detail.exe"
        p.StartInfo.Arguments = txtSummary_ManualDate.Text
        p.StartInfo.CreateNoWindow = False
        p.Start()
        p.WaitForExit()

        If rdlEmail_or_Display_Summary_Report.Items(0).Selected = True Then     'Email to recipients
            'Call code to email report to recipients
        Else                                                                    'Display report on screen
            Session("mSales_Date_Parm") = txtSummary_ManualDate.Text
            Response.Redirect("rptStoresFlashSummary.aspx")
        End If
    End Sub


===========================================================================================

Here is the aspx code:

<%@ Page Title="Retail Reports" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Retail_Reports.aspx.vb"
 Inherits="_Default" ViewStateMode="Inherit" Debug="true" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Headers" Runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:Label ID="lblPageName" runat="server" Text="Retail Reports" style="position:absolute; top:61px; left:833px; z-index: 1;
                visibility:visible; height: 20px; width: 290px; font-size:xx-large; color: Maroon; text-align:right" >
            </asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>     
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:tabcontainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
                style="position:absolute; top:170px; left:175px; z-index: 1; visibility:visible; "
                    ForeColor="Maroon" Height="600px" Width="950px">

                <asp:TabPanel ID="Stores_Flash_Summary" runat="server" HeaderText="Stores Flash Summary"
                    style="height: 220px; width: 700px">
                    <ContentTemplate>
                        <asp:Panel ID="Panel1" runat="server" BorderColor="Maroon" BorderStyle="Solid" 
                            BorderWidth="1px" Height="130px" Width="895px"
                            style="position:absolute; top:45px; left:25px">
                            <asp:Label ID="Label1" runat="server" Text="Schedule:" Font-Underline="True" Font-Bold="True" 
                                style="position:absolute; top:10px; left:10px;"></asp:Label>
                            <asp:RadioButtonList ID="rdlSummary_AutoOrManual" runat="server" AutoPostBack="True"
                                onselectedindexchanged="rdlSummary_AutoOrManual_SelectedIndexChanged"
                                style="position:absolute; top:30px; left:30px;">
                                <asp:ListItem Text="Automatic" Value="Auto" Selected="True" />
                                <asp:ListItem Text="Manual" Value="Manual" />
                            </asp:RadioButtonList>
                        </asp:Panel>   

                        <asp:Panel ID="pnlSummary_Automatic" runat="server" Height="130px" Width="770px"
                            style="position:absolute; top:45px; left:150px" BorderColor="Maroon" 
                            Visible="False" BorderStyle="None" BorderWidth="1px" Font-Bold="False">
                            <asp:Label ID="Label2" runat="server" Text="Run daily at this time:"
                                style="position:absolute; top:37px; left:70px"></asp:Label>                                                           
                            <asp:TextBox ID="txtSummary_AutoRunTime" runat="server" 
                                style="position:absolute; top:36px; left:260px" BorderWidth="1px" 
                                BorderColor="Maroon" Height="18px" Width="80px" Font-Bold="True" 
                                ForeColor="Green" ToolTip="Enter the hour, minute, and 'am' or 'pm'"></asp:TextBox>
                            <asp:Label ID="Label8" runat="server"
                                style="position:absolute; top:37px; left:350px" ForeColor="Red" Visible="False" Font-Bold="True"></asp:Label>     
                            <asp:Label ID="Label6" runat="server" Text="hh:mm am/pm, i.e. 7:15 am"
                                style="position:absolute; top:60px; left:262px" ForeColor="#999999"></asp:Label>
                            <asp:Button ID="btnSummary_Save" runat="server" Text="Save" Height="30px" Width="70px"
                                style="position:absolute; top:93px; left:95px" 
                                ToolTip="Click to save this Summary report setting" />  
                        </asp:Panel>

                        <asp:Panel ID="pnlSummary_Manual" runat="server" Height="130px" Width="770px"
                            style="position:absolute; top:45px; left:150px" BorderColor="Maroon" 
                            Visible="False" BorderStyle="None" BorderWidth="1px">
                            <asp:Label ID="Label4" runat="server" Text="Run now through this day:"
                                style="position:absolute; top:37px; left:70px"></asp:Label>
                            <asp:Label ID="Label19" runat="server" Text="Processing request..." Visible="false"
                                style="position:absolute; top:60px; left:70px; color:Red; font-weight:bold"></asp:Label>                                                           
                            <asp:TextBox ID="txtSummary_ManualDate" runat="server" 
                                style="position:absolute; top:36px; left:260px" BorderWidth="1px" 
                                BorderColor="Maroon" Height="18px" Width="80px" Font-Bold="True" 
                                ForeColor="Green"></asp:TextBox>
                            <asp:Label ID="Label9" runat="server"
                                style="position:absolute; top:37px; left:350px" ForeColor="Red" Visible="False" Font-Bold="True"></asp:Label>
                            <asp:Label ID="Label7" runat="server" Text="mm/dd/yyyy, i.e. 3/27/2011"
                                style="position:absolute; top:60px; left:262px" ForeColor="#999999"></asp:Label>     
                            <asp:CalendarExtender ID="CalendarExtender1" runat="server" 
                                TargetControlID="txtSummary_ManualDate" Enabled="True" PopupPosition="Right"></asp:CalendarExtender>
                            <asp:RadioButtonList ID="rdlEmail_or_Display_Summary_Report" runat="server" AutoPostBack="True"
                                onselectedindexchanged="rdlEmail_or_Display_Summary_Report_SelectedIndexChanged"
                                style="position:absolute; top:80px; left:255px;">
                                <asp:ListItem Text="Email report to all scheduled recipients below 'OR'" Value="All_Scheduled" />
                                <asp:ListItem Text="Display report on screen" Value="Only_Selected" Selected="True" />
                            </asp:RadioButtonList>
                            <asp:Button ID="btnSummary_Start" runat="server" Text="Start" Height="30px" Width="70px"
                                style="position:absolute; top:93px; left:95px" 
                                ToolTip="Click to begin running this Summary report" />
                        </asp:Panel>  

...

Open in new window

Avatar of EYoung

ASKER

If I only have this line:  "Label19.Visible = True" in the click event section, then Label19 does become visible.  But once I add any additional code to the click event section, that code has to execute before Label19 becomes visible.

I even tried moving the extra code to another procedure section and called it from the button click event but it too needed to execute before Label19 became visible.
So, the issue is that you first want to notify the user and then execute the code, right?

A piece of advice, notifying the user is redundant because the user Clicked the button, so it expects to see some action happening.

But, if it is something like you want the user to notify that something is happening and that the user must wait for the action to finish, Please use ModalPopupExtnder control in AJAX Control Toolkit.

Here: http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

If these two are not situations, can you please explain why you want to show the label and then execute the handling code?? Only then, I will be able to help you. ..
Avatar of EYoung

ASKER

Correct.  As soon as the user clicks the button, I want to display a message, i.e. make Label19 visible.

Regarding the redundancy, when the user clicks the button, nothing changes on the screen for several minutes until the process completes.  During that time I don't want the user to wonder if they clicked the button or if anything is happening.

You're correct in assuming that I want the user to be notified that something is happening and that the user must wait for the action to finish.  I will check out the ModalPopupExtender control tomorrow when I get back to work.

Thank you for the help.
You are welcome ... :)
Also, if you find the answer satisfactory, please do mark it as the Solution.
Thanks
Avatar of EYoung

ASKER

OK I have implemented the ModalPopupExtnder control in AJAX Control Toolkit and it now shows a popup window in the bottom right corner of the screen.  However, it does not solve my original request.  All it does is to display a modal popup that forces the user to click the OK button.  Then once clicked, the original process is not run.

What I originally wanted to achieve was to let the user know that their request is being processed once they click the Start button and to wait until it completes.  I thought I could achieve that by displaying a label on the screen while the process is running and remove the label once the process completes.

The ModalPopupExtender does not seem to accomlish that unless I am missing something.

Attached is the asp code used to display the popup.
<asp:ModalPopupExtender ID="MPE" runat="server"
                                BackgroundCssClass="modalBackground"
                                TargetControlID="btnSummary_Start"
                                PopupControlID="Panel3"
                                DropShadow="True" 
                                OkControlID="btnOk"
                                PopupDragHandleControlID="Panel3" DynamicServicePath="" 
                                Enabled="True" />
                                
                            <asp:Panel ID="Panel3" runat="server" CssClass="modalPopup"
                                style="top:10px; left:10px; height:80px; width:190px; color:Red; font-weight:bold"> 
                                <asp:Label ID="Label19" runat="server" Text="Processing request..."
                                    style="position:relative; top:15px; left:20px;"></asp:Label>
                                    <br /><br /> 
                                    <asp:Button ID="btnOk" runat="server" Text="Ok"
                                        style="position:relative; top:15px; left:80px;" />
                            </asp:Panel>

Open in new window

Avatar of EYoung

ASKER

Here is a summary of what I want to achieve:

1.  User clicks the Start button.

2.  I make Label19.Visible=True on the screen that says a process is running and to wait.

3.  When the process completes, I set Label19.Visible=False.

4.  User continues on with other tasks.

That is all there is to this issue.

The problem I am having is that when the user clicks the Start button, a postback is generated, and the page_load is run which re-renders the page.  Since I can not set Label19.Visible=True in the Start button's click event  because the page is already re-rendered, I have to set Label19.Visible=True in the page_load event and to do that I have to know which button generated the postback.

All I want to do is to somehow notify the user that something is happening and then when that something is done, I want to remove the notification message.  

Hi buddy, I think what do you want to do is easy to achieve,  try this example:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'Simulate work
        System.Threading.Thread.Sleep(1000)
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Submitting Demo</title>
    <script type="text/javascript">
        function showWait() {
            document.getElementById('lblWaitMessage').style.display = '';
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center;">
        <asp:Label Text="Wait please..." runat="server" ID="lblWaitMessage" ClientIDMode="Static"
            Style="display: none;" />
        <br />
        <asp:Button ID="btn_Submit" runat="server" Text="Start" Width="100px" OnClientClick="showWait()" />
    </div>
    </form>
</body>
</html>

Open in new window


Download the aspx from this link:
ShowWaitDemo.aspx

I hope this help.
Please tell me if you need help to integrate this with ajax, the concept is the same for ajax, but you need to consider others aspects. If the example above is what do you want to do in ajax, that can be done without problems.
Also you can do this:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'Simulate work
        System.Threading.Thread.Sleep(1000)
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Show Wait Demo</title>
    <script type="text/javascript">
        function showWait(text) {
            var obj = document.getElementById('lblWaitMessage');
            obj.style.display = '';
            obj.innerHTML = text;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center;">
        <span id="lblWaitMessage" style="display: none;"></span>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Start 1" Width="100px" OnClientClick="showWait('Waiting for Start 1 process...')" />
        <asp:Button ID="Button2" runat="server" Text="Start 2" Width="100px" OnClientClick="showWait('Waiting for Start 2 process...')" />
        <asp:Button ID="Button3" runat="server" Text="Start 3" Width="100px" OnClientClick="showWait('Waiting for Start 3 process...')" />
    </div>
    </form>
</body>
</html>

Open in new window

Avatar of Craig Wagner
I created the following extension method to figure out what control caused a postback. It's in C# so you can either convert it to VB.NET or just create a C# project and add it to your solution.
public static class PageExtensions
    {
        public static Control GetPostBackControl( this Page page )
        {
            Control control = null;
            string ctrlname = page.Request.Params["__EVENTTARGET"];
            if( ctrlname != null && ctrlname != String.Empty )
            {
                control = page.FindControl( ctrlname );
            }
            else
            {
                // if __EVENTTARGET is null, the control is a button type and we need to 
                // iterate over the form collection to find it
                string ctrlStr = String.Empty;
                Control c = null;
                foreach( string ctl in page.Request.Form )
                {
                    // handle ImageButton controls ...
                    if( ctl.EndsWith( ".x" ) || ctl.EndsWith( ".y" ) )
                    {
                        ctrlStr = ctl.Substring( 0, ctl.Length - 2 );
                        c = page.FindControl( ctrlStr );
                    }
                    else
                    {
                        c = page.FindControl( ctl );
                    }
                    if( c is Button || c is ImageButton )
                    {
                        control = c;
                        break;
                    }
                }
            }
            return control;
        }
    }
}

Open in new window

Hi again, this is the same example but by using ajax, it works out of the box :)
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'Simulate work
        System.Threading.Thread.Sleep(1000)
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Show Wait Demo</title>
    <script type="text/javascript">
        function showWait(text) {
            var obj = document.getElementById('lblWaitMessage');
            obj.innerHTML = text;
            obj.style.display = '';
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="text-align: center;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <span id="lblWaitMessage" style="display: none;"></span>
                <br />
                <asp:Button ID="Button1" runat="server" Text="Start 1" Width="100px" OnClientClick="showWait('Please wait, process 1 is executing...')" />
                <asp:Button ID="Button2" runat="server" Text="Start 2" Width="100px" OnClientClick="showWait('Please wait, process 2 is executing...')" />
                <asp:Button ID="Button3" runat="server" Text="Start 3" Width="100px" OnClientClick="showWait('Please wait, process 3 is executing...')" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

Open in new window


Here the aspx demo file:
ShowWaitDemo.aspx
Avatar of EYoung

ASKER

yv989c - I have copied your code above for the "showWait" function but it is generating an error.  I think this code may fix my issue but just needs some fine tuning.

Below is the code in my aspx file showing both the "showWait" function and the label and the button.  I changed the "span" control to a label control.  As a reminder, I am using VB and not C.

Also attached is a screen shot of the error message.

Thank you for the help.
<%@ Page Title="Retail Reports" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Retail_Reports.aspx.vb"
 Inherits="_Default" ViewStateMode="Inherit" Debug="true" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Headers" Runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:Label ID="lblPageName" runat="server" Text="Retail Reports" style="position:absolute; top:61px; left:833px; z-index: 1;
                visibility:visible; height: 20px; width: 290px; font-size:xx-large; color: Maroon; text-align:right" >
            </asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>     
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Body" Runat="Server">


(Here is the function) ==================================================================

<script type="text/javascript">
    function showWait(text) {
        var obj = document.getElementById('lblWaitMessage_Summary');
        obj.innerHTML = text;
        obj.style.display = '';
    }
</script>

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <asp:tabcontainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
                style="position:absolute; top:170px; left:175px; z-index: 1; visibility:visible; "
                    ForeColor="Maroon" Height="600px" Width="950px">

                <asp:TabPanel ID="Stores_Flash_Summary" runat="server" HeaderText="Stores Flash Summary"
                    style="height: 220px; width: 700px">
                    <ContentTemplate>
                        <asp:Panel ID="Panel1" runat="server" BorderColor="Maroon" BorderStyle="Solid" 
                            BorderWidth="1px" Height="130px" Width="895px"
                            style="position:absolute; top:45px; left:25px">
                            <asp:Label ID="Label1" runat="server" Text="Schedule:" Font-Underline="True" Font-Bold="True" 
                                style="position:absolute; top:10px; left:10px;"></asp:Label>
                            <asp:RadioButtonList ID="rdlSummary_AutoOrManual" runat="server" AutoPostBack="True"
                                onselectedindexchanged="rdlSummary_AutoOrManual_SelectedIndexChanged"
                                style="position:absolute; top:30px; left:30px;">
                                <asp:ListItem Text="Automatic" Value="Auto" Selected="True" />
                                <asp:ListItem Text="Manual" Value="Manual" />
                            </asp:RadioButtonList>
                        </asp:Panel>   

                        <asp:Panel ID="pnlSummary_Automatic" runat="server" Height="130px" Width="770px"
                            style="position:absolute; top:45px; left:150px" BorderColor="Maroon" 
                            Visible="False" BorderStyle="None" BorderWidth="1px" Font-Bold="False">
                            <asp:Label ID="Label2" runat="server" Text="Run daily at this time:"
                                style="position:absolute; top:37px; left:70px"></asp:Label>                                                           
                            <asp:TextBox ID="txtSummary_AutoRunTime" runat="server" 
                                style="position:absolute; top:36px; left:260px" BorderWidth="1px" 
                                BorderColor="Maroon" Height="18px" Width="80px" Font-Bold="True" 
                                ForeColor="Green" ToolTip="Enter the hour, minute, and 'am' or 'pm'"></asp:TextBox>
                            <asp:Label ID="Label8" runat="server"
                                style="position:absolute; top:37px; left:350px" ForeColor="Red" Visible="False" Font-Bold="True"></asp:Label>     
                            <asp:Label ID="Label6" runat="server" Text="hh:mm am/pm, i.e. 7:15 am"
                                style="position:absolute; top:60px; left:262px" ForeColor="#999999"></asp:Label>
                            <asp:Button ID="btnSummary_Save" runat="server" Text="Save" Height="30px" Width="70px"
                                style="position:absolute; top:93px; left:95px" 
                                ToolTip="Click to save this Summary report setting" />  
                        </asp:Panel>

                        <asp:Panel ID="pnlSummary_Manual" runat="server" Height="130px" Width="770px"
                            style="position:absolute; top:45px; left:150px" BorderColor="Maroon" 
                            Visible="False" BorderStyle="None" BorderWidth="1px">
                            <asp:Label ID="Label4" runat="server" Text="Run now through this day:"
                                style="position:absolute; top:37px; left:70px"></asp:Label>  
                            <asp:TextBox ID="txtSummary_ManualDate" runat="server" 
                                style="position:absolute; top:36px; left:260px" BorderWidth="1px" 
                                BorderColor="Maroon" Height="18px" Width="80px" Font-Bold="True" 
                                ForeColor="Green"></asp:TextBox>
                            <asp:Label ID="Label9" runat="server"
                                style="position:absolute; top:37px; left:350px" ForeColor="Red" Visible="False" Font-Bold="True"></asp:Label>
                            <asp:Label ID="Label7" runat="server" Text="mm/dd/yyyy, i.e. 3/27/2011"
                                style="position:absolute; top:60px; left:262px" ForeColor="#999999"></asp:Label>     
                            <asp:CalendarExtender ID="CalendarExtender1" runat="server" 
                                TargetControlID="txtSummary_ManualDate" Enabled="True" PopupPosition="Right"></asp:CalendarExtender>
                            <asp:RadioButtonList ID="rdlEmail_or_Display_Summary_Report" runat="server" AutoPostBack="True"
                                onselectedindexchanged="rdlEmail_or_Display_Summary_Report_SelectedIndexChanged"
                                style="position:absolute; top:80px; left:255px;">
                                <asp:ListItem Text="Email report to all scheduled recipients below 'OR'" Value="All_Scheduled" />
                                <asp:ListItem Text="Display report on screen" Value="Only_Selected" Selected="True" />
                            </asp:RadioButtonList>
                                

(Here is the Label and Button)==============================================================

                
                            <asp:Label ID="lblWaitMessage_Summary" runat="server"
                                style="position:absolute; top:60px; left:70px; display:none" ForeColor="Red" Font-Bold="true"></asp:Label> 
                            <asp:Button ID="btnSummary_Start" runat="server" Text="Start" Height="30px" Width="70px"
                                style="position:absolute; top:93px; left:95px"
                                ToolTip="Click to begin running this Summary report"
                                OnClientClick="showWait('Processing.  Please Wait...')"/>

                        </asp:Panel>
...

Open in new window

Error-message.JPG
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America 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
Avatar of EYoung

ASKER

yv989c - Maybe the problem I am having is due to my changing the span tag to a label tag?

The challenge I am having is that the buttons that the user can click on the form can be on different places in the web form and on different panels.  They are not all grouped together as in your example.

For example, there is an Summary panel and a Detail panel that the user can go to in order to see a Summary Report or a Detail Report.  Each panel has a start button on it that starts the Summary or Detail processing and report.  The user can click either button and when clicked, I want to display the "Please wait..." message while the processing is occurring.  Once the processing completes, the report displays and the message should disappear.

So how do I use the "showWait" function to display the message?

Thank you for the help.
Avatar of EYoung

ASKER

Yes, that fixed the issue.  The message is working exactly how I want it to work.

With that said, I don't understand how it works.  Can you explain it further?

Thank you again for all the help and for sticking with me on this.

My thanks to everyone else.
Hi, did you see my last post? I think that fit all yours scenarios.

My english is not very good, so in my last post it must read:

In summary, set your label control ClientIDMode property to "Static".
Avatar of EYoung

ASKER

Yes, I saw your last post.  Our messages just overlapped and your english is fine.
Hi again, I will try to explain this in a simple way:

First, we need understand what is a post-back in the asp.net world, in resume, is when your page fires a event (like clicking a button) that will post data to the server and then the server send a response go back to the client web browser, that in simple terms is a post-back (a round trip).

Why yours first attempts to do this failed? well, you are visualizing this from the aspnet server logic, you want it happens before reach the server (display your label), so setting the aspnet label.Visible attribute to true will not have the desired behavior.

To accomplish this you will need to rely in client side script, how? like in the example, the button OnClientClick property will render on your page the onclick event for your button with the customized call to the javascript function showWait, when you click the button, that code will execute immediately (showWait function), then we use a little trick for your label, set the visible style attribute to none, it is always be hided, so when the showWait is called it will remove this style from your label, making it visible, when the server response is received your page is reloaded with this response and your label control is restored to it original state.

I hope this explanation help you to understand this a little more, I want to give more details but my english is limited.

Also, I want to let you know there is the UpdateProgress control, this will appears when you do a postback on an ajax update panel control, it can be defined like the next example:
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
        <span>Wait please...</span>
    </ProgressTemplate>
</asp:UpdateProgress>

Open in new window


But some times it default behavior is annoying, so you need to implement your own notification mechanism.
Avatar of EYoung

ASKER

Excellent explanation.  Thank you so much.  I am from the WinForm world and so WebForms and PostBacks are such a new concept.  Regards, EYoung
Glad to help buddy
Avatar of EYoung

ASKER

Are you saying that a post-back is the full round trip from the client to the server and back to the client?

I thought it was just from the client to the server?

Thanks
Hi, you are right, a post-back as it name says, represent only post back data to the server, in an aspnet page (aspx) by default the server always generate a response to the client (unless that you change that behavior by code), that is why I said that, in a simple way.
Avatar of EYoung

ASKER

OK, I get it.  Thanks so much for the help.
You are welcome