Modal dialog windows position on postback

Discussion in 'Javascript' started by Rod, Apr 14, 2005.

  1. Rod

    Rod Guest

    I have an asp.net application where some of the interaction with the
    user is through modal dialog windows. This works very well except for
    the annoying fact that the dialog window always returns to its initial
    position when the user posts back (by clicking a button, etc.)

    I have all of the fundamentals for asp.net modal dialogs in place, such
    as using <base target="_self"> in the header...

    To reiterate the problem for the sake of clarity: The users would like
    to be able to reposition the modal dialogs and have the dialog maintain
    its position when a postback is caused via clicking a button, etc.
    Instead the modal dialog always returns to the position where it was
    initally created.

    What technique can I use to have the modal dialg remember its position
    on postback.

    This is an important issue for my client. I will post to this
    newsgroup the solution I find (whether by assistance from
    comp.lang.javascript, etc. -- or by my research).

    Thanks,
    Rod
    Rod, Apr 14, 2005
    #1
    1. Advertising

  2. Rod

    Rod Guest

    I have found a 90% solution for how to get a modal dialog to maintain
    its position after postback. (More later on the remaining 10%.)

    In a nutshell, when the user clicks a button or other control that
    causes a postback/submit, I retain the window.screenLeft and .screenTop
    in hidden text inputs, and include script to set the window.dialogLeft
    and .dialogTop in the response.

    This is not a 100% solution. The dialog maintains its postion, but if
    you move the dialog and then do a submit/postback, it will jump back to
    its original (prior to moving the dialog) position for a brief moment
    until the positioning script is run to place it to where you moved it.
    I haven't figured out how to overcome that, so I appreciate any
    suggestions or ideas.

    Now for more details. First of all, this is an ASP.Net appliction with
    VB.Net as the server-side codebehind langauge. In the dialog, I have
    two hidden <aspnet:textbox runat="server"> controls whose IDs are
    hidXPos and hidYPos, respectively.

    I have a javascript function whose purpose is to retain the current
    window position. It is placed in the onclick event handler for any
    control that does a submit/postback -- prior, of course, to doing the
    submit.

    function RecordPosition() {
    var ohidXPos = document.getElementById('hidXPos');
    var ohidYPos = document.getElementById('hidYPos');

    ohidXPos.value = window.screenLeft;
    ohidYPos.value = window.screenTop;
    }


    In the server-side code-behind, the Page_Load sub, which handles the
    Page Load event, contains the following code snippit. Notice that I
    subtract 3 pixels from dialogLeft and 22px from dialogTop to compensate
    for thw window border and caption bar.


    If hidXPos.Text <> "" And hidYPos.Text <> "" Then
    Dim strScr As New System.Text.StringBuilder
    strScr.Append("<script language='javascript'>" & vbNewLine)
    strScr.Append("window.dialogLeft = '")
    strScr.Append(hidXPos.Text - 3)
    strScr.Append("';" & vbNewLine)
    strScr.Append("window.dialogTop = '")
    strScr.Append(hidYPos.Text - 22)
    strScr.Append("';" & vbNewLine)
    strScr.Append("</script>" & vbNewLine)
    RegisterStartupScript("position", strScr.ToString)
    End If


    This produces script that looks like the following, for example:

    <script language='javascript'>
    window.dialogLeft = '259';
    window.dialogTop = '117';
    </script>


    Another idea I tried unsuccessfully was to set window.dialogLeft and
    Top in the above RecordPosition function. That seemed to have no
    effect.

    Thanks,
    Rod
    Rod, Apr 14, 2005
    #2
    1. Advertising

  3. Rod

    kaeli Guest

    In article <>,
    enlightened us with...
    >
    > To reiterate the problem for the sake of clarity: The users would like
    > to be able to reposition the modal dialogs and have the dialog maintain
    > its position when a postback is caused via clicking a button, etc.
    > Instead the modal dialog always returns to the position where it was
    > initally created.
    >
    > What technique can I use to have the modal dialg remember its position
    > on postback.
    >


    Is this postback occuring in the parent window or the modal dialog?

    --
    --
    ~kaeli~
    If the funeral procession is at night, do folks drive with
    their lights off?
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Apr 14, 2005
    #3
  4. Rod

    Rod Guest

    The postback is occuring in the modal dialog.
    Rod, Apr 14, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    1
    Views:
    510
    Bruce Barker
    Mar 17, 2005
  2. Leila
    Replies:
    0
    Views:
    390
    Leila
    Apr 26, 2005
  3. Matt
    Replies:
    1
    Views:
    3,123
    Whitecrest
    Jun 1, 2004
  4. JR
    Replies:
    0
    Views:
    324
  5. Don
    Replies:
    0
    Views:
    341
Loading...

Share This Page