×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hidden div shwoing when back button is clicked

Hidden div shwoing when back button is clicked

Hidden div shwoing when back button is clicked

(OP)
Hello,

I have a div in an aspx (vb .net 4.5) page:

CODE --> asp

<div id="Div1" runat="server" class="shaded" style="display:none;"> </div> 

When an ImageButton is clicked, it shows the div from code-behind:

CODE --> vb

Private Sub ImageButton1_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton1.Click

        Me.Div1.Attributes.Add("style", "display:block")

End Sub 

For some reason, when a person hits the back button in the browser, this hidden div is always shown again. I have even put code in the Page Load to try getting round this.

Can anyone help?

Thanks

RE: Hidden div shwoing when back button is clicked

(OP)
Sorry, css:

CODE --> css

.shaded {
    left: 0;
    top: 0; 
    width: 100%;
    height: 100%; /*position:relative; */
    opacity: 0.8;
    filter: alpha(opacity=80); /* For IE8 and earlier */
    background-color: #000000;
    z-index: 995;
    position: absolute;
} 

RE: Hidden div shwoing when back button is clicked

Documents read from the browser cache do not trigger onload events or reload CSS, whatever state they were in, is what they come back as. "Back" simply restores the previous DOM image as it was.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Hidden div shwoing when back button is clicked

(OP)
But why does the div show? Is there anything I can do to ensure it doesn't? It only shows on hitting back, not if you click the home button for example.

It seems somewhat random. If someone clicks on the button to show the div and then closes it again, it will re-show on returning to the page every single time, but then sometimes it will show anyway even if it had previously not been triggered.

Most odd.

RE: Hidden div shwoing when back button is clicked

Using the "home" button/link reloads the URL from the server, the back button doesn't.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Hidden div shwoing when back button is clicked

(OP)
An actual suggestion would have been welcome.

RE: Hidden div shwoing when back button is clicked

To do what??

There is no IfLoadedFromCache event to hook into, so you cannot make a browser re-render the page if has been loaded from history(-1).

What loads from the cache is what it is, and there isn't a whole lot you can do about it.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Hidden div shwoing when back button is clicked

Hey silly question (and yes I know i'm slow to respond :) ),

as your div is absolutely positioned anyway, have you tried simply setting both top and left to negative numbers and specifying a width ... e.g.:

CODE --> CSS

.shaded {
    left: -800px;
    top: -800px; 
    width: 700px;
    height: 700px; /*position:relative; */
    opacity: 0.8;
    filter: alpha(opacity=80); /* For IE8 and earlier */
    background-color: #000000;
    z-index: 995;
    position: absolute;
} 

then change your onclick to something like this:

CODE --> vb

Private Sub ImageButton1_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton1.Click

        Me.Div1.Attributes.Add("style", "display:block")
        Me.Div1.Attributes.Add("style", "left:0px")
        Me.Div1.Attributes.Add("style", "top:0px")
        Me.Div1.Attributes.Add("style", "height:100%")
        Me.Div1.Attributes.Add("style", "width:100%")

End Sub 

sorry if the syntax is nasty (personally I'd just do this in javascript rather than ask ASP to generate the javascript for me wink) but I find that provided you get your CSS states correct it should work... of course the first thing to try is to simply specify that the div should be hidden by appending a display attribute to your initial CSS ... something like:

CODE --> CSS

.shaded {
    left: 0;
    top: 0; 
    width: 100%;
    height: 100%; /*position:relative; */
    opacity: 0.8;
    filter: alpha(opacity=80); /* For IE8 and earlier */
    background-color: #000000;
    z-index: 995;
    position: absolute;
    display: none;
} 

or considering you're heading back a step, why not on form submission ensure the style is set to display:none (e.g. your forms submit button can have an onclick that does this.)

There are literally many ways to combat this scenario, not sure it's still an issue as i'm sure by now you've found a solution, but I noticed your post which read:

Quote (Hfnet)

An actual suggestion would have been welcome
So I figured I might as well give you one or two wink

hfh

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close