Solved

Show Hide DIV or Panel after Postback

Posted on 2011-02-28
11
4,737 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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