Results 1 to 10 of 10

Thread: Keeping a Div Visable after postback

  1. #1
    Junior Member
    Join Date
    Oct 07
    Posts
    22

    Keeping a Div Visable after postback

    I'm having issues with figuring out a way to keep a div visible after a post back.

    I have a button on the form, when clicking the button a div that was style="visibility:hidden;" is set to style="visibility:visible" via java script.

    Inside of this div is a asp.net Calender control, when I switch months the control posts back and the div is hidden again. How do I keep the div visible until a date is selected on the calender?

    Thanks,


    Bradley

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 04
    Location
    at my desk
    Posts
    2,467

    Re: Keeping a Div Visable after postback

    If your div is built as a server control (i.e. <div id="myDiv" runat="server") then you can do a check on the page's Load event for a post back:
    Code:
    If IsPostBack Then
      'whatever checks to see if it should still be visible
    End If

  3. #3
    Junior Member
    Join Date
    Oct 07
    Posts
    22

    Re: Keeping a Div Visable after postback

    Okay I have tried to Check if the visibility is set or not on the pageload

    Code:
             if Page.IsPostBack then
                    'DCalStart is the Div id
                    If DCalStart.Style.Value.Contains("visible") Then
                        DCalStart.Style.Value = "display: inline; visibility: visible;"
                    Else
                        DCalStart.Style.Value = "display: none; visibility: hidden;"
                    End If
             End If
    But no matter when I check it, it always comes back as being hidden. Am I checking the wrong place?

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 04
    Location
    at my desk
    Posts
    2,467

    Re: Keeping a Div Visable after postback

    I'd suggest monitoring progress with session variables or something similar. If the page is set to load with visibility:hidden, then that's what'll always return. Page values aren't a good thing to monitor progress with.

  5. #5
    Junior Member
    Join Date
    Oct 07
    Posts
    22

    Re: Keeping a Div Visable after postback

    Well that's a funny thing, right now they are set to load with visibility set to visible, and they still show up as hidden after any post back. I'll give the Session variable a try and see if I get better results with that approach.

    -Bradley

  6. #6
    Junior Member
    Join Date
    Oct 07
    Posts
    22

    Re: Keeping a Div Visable after postback

    Can you show me a brief example of this or point me to a good reference of how to accomplish this? I thought I understood Session variables but I guess I don't. How do I a session variable to remember if a Div is visible or not? I understand how to access the value, but how do I set it on the client before the post back?

  7. #7
    Banned timeshifter's Avatar
    Join Date
    Mar 04
    Location
    at my desk
    Posts
    2,467

    Re: Keeping a Div Visable after postback

    If it's a step-by-step operation that the user is being led through, just track how far they've come with an int or something like that.

  8. #8
    PowerPoster
    Join Date
    Oct 02
    Location
    British Columbia
    Posts
    9,758

    Re: Keeping a Div Visable after postback

    Why use Session variables? If the Calendar control causes the Postback a Calendar event will fire. Since the user was able to click the calendar, the Div is visible. Set the style in the Calendar event...

  9. #9
    Junior Member
    Join Date
    Oct 07
    Posts
    22

    Re: Keeping a Div Visable after postback

    Thanks brucevde that solution worked like I was hoping it would. I don't know why I didn't think of that. Guess I was trying to make it harder than it needed to be.



    -Bradley

  10. #10
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 03
    Location
    Back in the doghouse
    Posts
    291

    Re: Keeping a Div Visable after postback

    You already have an answer but I'll post it anyway

    You might want to build a simple pop up calendar control.
    Pop & size it & position it. Then use window.opener.forms(0).... to set the date where you want it.

    There are several examples listed on various sites, unfortunately most constipatingly (should be a word ) complex (or in C#)

    I'll post some code if that's what your trying to do.
    Last edited by Rocketdawg; Nov 19th, 2007 at 03:54 PM. Reason: Already solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •