Solved

Show Hide DIV or Panel after Postback

Posted on 2011-02-28
11
4,585 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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
 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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