Solved

Show Hide DIV or Panel after Postback

Posted on 2011-02-28
11
4,499 Views
Last Modified: 2012-05-11
I am having difficulty showing a hidden DIV or ASP.net Panel on postback.

I submit a page that adds items to a database then sends an email.  Those items work perfect.  However, I want a message to show up saying that it was successful.  My understanding from what I have read is that if you are using a Panel with visibility set to False that it will not be rendered, therefore you cannot set it back to visibile from the server side.  

I've also tried setting the DIV style via javascript and have not been successful.

As the insert to the database takes place an ajax update panel does show.  But for some reason the portion to show the "success" message  will not trigger.

I know that I am rambling, but just frustrated.

Here is the portion that should show after the insert and email "Success Message":
(currently set for trying to change the style. Tried visibility:hidden/visible too)
 
<div id="SubmittedPanelWrapper" runat="server" style="display: block" >
             <div id="SubmittedBackgroundFilter"></div>
            <div id="SubmittedMessage"> 
                
                         <center> 
                          The change has been submitted.<br /> You will receive an email once the change is complete.<br /> <br />
                             <asp:Button ID="SubmittedOK" runat="server" Text="OK" CssClass="submitButton" />
                         </center> 
                            </div>
                         </div>

Open in new window


Associated CSS for the Success Message:
 
#SubmittedBackgroundFilter {
    position:fixed;
    top:0px;
    bottom:0px;
    left:0px;
    right:0px;
    overflow:hidden;
    padding:0;
    margin:0;
    background-color:#000;
    filter:alpha(opacity=50);
    opacity:0.5;
    z-index:1000;
}#SubmittedMessage {
    position:fixed;
    top:30%;
    left:43%;
    padding:10px;
    width:14%;
    z-index:1001;
    background-color:#fff;
    border:solid 1px #000;
}
.submitButton
{
    text-align: right;
    padding-right: 10px;
}

Open in new window



The submit button (visibile set to true from code behind once certain criteria are met, works):
 
<asp:Button ID="SubmitButton" runat="server" Text="Submit Changes"  
                style="text-align: center" Visible="false" 
                "/>

Open in new window


The Sub:
 
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
        SqlDataSourceInsertClientUpdate.Insert() ' <- Works 
        SendIANotificationEmail()  ' <- Works
        ' This is where I would set a trigger to show the "Success" Message
        ' I've tried SubmittedPanelWrapper.Style.Add("display", "block")
        ' I've tried this with a panel as well.
        ' I've tried PanelChangeSubmitted.visible = True  ** The panel code is no longer in the aspx page.  But this is how I tried to activate it when it was.
        ' I've tried setting the style by javascript and using the onClientClick.

    End Sub

Open in new window


I have even setup a new asp button and tried to trigger off of it, thinking it had something to do with the timing of the postback.  But it didn't work either.

Any help in the right direction would be appreciated.
0
Comment
Question by:ITMcmcpa
  • 6
  • 4
11 Comments
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 34999640
If you want to control  <div id="SubmittedMessage">  from code behind for visibility then add runat="server" tag, you will be able to access div from code behind.

 <div id="SubmittedMessage" runat="server">


code behind
---------------

SubmittedMessage.visible=false
0
 

Author Comment

by:ITMcmcpa
ID: 34999710
Unfortunately that does not work. SubmittedPanelWrapper has the runat="server" and I can access the visibile attribute from the Code Behind, but it does not trigger.  There is no error message.
0
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 34999836
Please post code where you have made panel's visibility false/true and also your page_load event too.
0
 

Author Comment

by:ITMcmcpa
ID: 34999936
This is how I tried setting up the panel:
 
<asp:Panel ID="PanelChangeSubmitted" runat="server" Visible="false">
     <div id="SubmittedPanelWrapper" runat="server" >
             <div id="SubmittedBackgroundFilter"></div>
            <div id="SubmittedMessage"> 
                
                         <center> 
                          The change has been submitted.<br /> You will receive an email once the change is complete.<br /> <br />
                             <asp:Button ID="SubmittedOK" runat="server" Text="OK" CssClass="submitButton" />
                         </center> 
                            </div>
                         </div>
                         </asp:Panel>

Open in new window


The Submit Button:
 
Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitButton.Click
        SqlDataSourceInsertClientUpdate.Insert() ' <- Works 
        SendIANotificationEmail()  ' <- Works
        PanelChangeSubmitted.Visible = True ' <-doesn't work
    End Sub

Open in new window


page_load:
 
'set logged in user for credential validation
      


        Dim CurrentUserName As String = Environment.UserName
        Try
            TBUser.Text = Session("loggedinas").ToString()
        Catch ex As Exception
            Response.Redirect("~/sessionint.aspx")
        End Try


        ' PanelChangeSubmitted.Visible = False
        LBLloggedInUserCPaaa.Text = CurrentUserName
        LBLwarning1aaa.Visible = True
        TBDateTimeofEntry.Text = Now()

        SetWarningLabel()



        'set title of page in the site.master
        Dim myLabel As Label
        myLabel = CType(Master.FindControl("LBLHeaderTitle"), Label)
        If Not myLabel Is Nothing Then

            myLabel.Text = "Client Update Form"
        End If



        'lookup rights for viewing update client list link

        Dim dvSqlCUlist As DataView =
       DirectCast(SqlDataSource4AccessClientUpdateList.Select(DataSourceSelectArguments.Empty), DataView)
        For Each drvSqlCUlist As DataRowView In dvSqlCUlist
            If drvSqlCUlist("userclientupdatelist").ToString() = "True" Then


                ListViewerHyperLink.Visible = True

            Else

                ListViewerHyperLink.Visible = False
            End If

        Next

    End Sub

Open in new window

0
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 35000135
can you try like below

// To hide:
 Panel1.Style.Add("display", "none");
// To show:
 Panel1.Style.Add("display", "block");
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:ITMcmcpa
ID: 35000144
I've tried it once.. but I will try again.
0
 
LVL 5

Expert Comment

by:sindhuxyz
ID: 35000158
before you try above; remove Visible="false" from panel
0
 

Author Comment

by:ITMcmcpa
ID: 35000160
right
0
 

Author Comment

by:ITMcmcpa
ID: 35000189
I put the hide in the page load.  It does hide the panel.  But the show does not work.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 35000230
You said you are using UpdatePanel correct? So if your postback is coming from UP and your message panel is outside of that panel, it won't be update. Make sure your MessagePanel is also inside of UP.
If that is not the case let us know.
0
 

Author Comment

by:ITMcmcpa
ID: 35000245
That was exactly it.  It works now.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now