Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Show Hide DIV or Panel after Postback

Posted on 2011-02-28
11
Medium Priority
?
4,908 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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 …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 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