Need to refresh page after calling showModalDialog

Discussion in 'ASP .Net' started by teddysnips@hotmail.com, Dec 23, 2005.

  1. Guest

    I have Search form that allows users to retrieve records into a
    DataGrid. There are two search criteria - a Month and a Year, which
    are selected from drop-down lists. There is a server-side button
    called "cmdFilter" which retrieves data from the database using any
    criteria thus selected.

    For any of the records retrieved into the grid match certain
    conditions, one of the columns will be formed into a hyperlink.
    Clicking on this will allow the user to display a modal dialog, at
    which point the user can manipulate the data displayed.

    The hyperlink is created server-side like so (in the ItemDataBound
    event):

    Dim drv As DataRowView = CType(item.DataItem, DataRowView)
    Dim Rule As String = CType(drv.Item(0), String)
    Return "<a style='COLOR:black' href='javascript:ShowUploadInfo(""" &
    Rule & """)'>Upload</a>"


    When the user closes the pop-up, I'd like the underlying form to be
    refreshed.

    Here's what I've done.

    In the .aspx file for the Search form (the "parent" or "calling" form)
    I have the following:

    function ShowUploadInfo(uploadDate) {

    // Save search variables
    //document.all.item("txtHiddenStartDate").value =
    document.all.item("txtStartDate").value;
    //document.all.item("txtHiddenEndDate").value =
    document.all.item("txtEndDate").value;
    //document.all.item("txtHiddenMonth").value =
    Number(document.getElementById('cboCalendarMonth').value);
    //document.all.item("txtHiddenYear").value =
    Number(document.getElementById('cboCalendarYear').value);

    var str =
    window.showModalDialog('../Popups/UploadInfo.aspx?uploadDate=' +
    uploadDate,'',
    'dialogHeight:800px;dialogWidth:805px;status=no,toolbar=no,menubar=no,resizable=no,location=no,scrollbars=no','','unadorned:yes');

    // POINT 1 POINT 1 POINT 1 POINT 1 POINT 1 POINT 1 POINT 1 POINT 1
    if (!str)
    {
    str = "";
    }

    if (str.length == 0)
    {
    return;
    }
    else
    {
    debugger;
    // attempt to execute cmdFilter.Click event in VB code behind
    document.all.item("cmdFilter").click();
    }
    // POINT 2 POINT 2 POINT 2 POINT 2 POINT 2 POINT 2 POINT 2 POINT 2
    }

    and in the "child" or "popup" form I have:

    <body onunload="SetUpCallingPage()">

    <SCRIPT language="javascript" id="Custom2">
    <!--
    function SetUpCallingPage()
    {
    window.returnValue = 1;
    }
    //-->
    </SCRIPT>

    The problem I'm having is twofold.

    Running as it is, when the pop-up is closed there is a postback of some
    sort on the "parent" or "closing" form, but the code at
    document.all.item("cmdFilter").click(); IS NOT CALLED - at least, the
    breakpoint at the start of the code is not hit (unlike, say, if I click
    on the button). Also, all the values that have been entered into the
    criteria controls (month and year) are lost or, rather, reset to their
    default values.

    If I remove the code between POINT 1 and POINT 2, it all seems to work
    well. The pop-up is displayed, the data can be manipulated in the
    pop-up, but of course when the pop-up is closed the "parent" or
    "calling" form is not refreshed or posted back to reflect changes to
    the underlying data. However, unlike in the above scenario the
    controls on the form remain unchanged.

    I tried using location.reload(true); in place of the
    document.all.item("cmdFilter").click(); but I got a message box which
    the clients won't like. I've also tried saving the criteria to a group
    of hidden controls and retrieving them in the code-behind, but since
    the code behind doesn't seem to be hit by the

    document.all.item("cmdFilter").click();

    there's little likelihood that this will work.

    Has anyone any ideas where I'm going wrong? It's driving me nuts!

    Anyway, happy Christmas (or whatever) to all our readers.

    Edward
    , Dec 23, 2005
    #1
    1. Advertising

  2. gnubslayer

    Joined:
    Jun 1, 2007
    Messages:
    1
    Location:
    Norfolk
    Refresh parent page after calling a modal

    I wrestled with this one for a while and found very few pages that were helpful.

    in the javascript where you call out to create the modal window,

    simply add the line
    -------------------------------------

    window.location = window.location;

    -------------------------------------


    after the call to the modal window.
    I know this seems stupidly simple but it works to refresh the current window.

    the reason this works is that the javascript that creates the modal window is temporarily suspended until control returns back to it. So when you return, performing that simple assignment points the web browser back to the page it was on when it returned from the modal window. which of course forces a reload of that page.

    Now if you were on a particular tab when you called out that modal, you could probably set the focus back to that tab. I havent figured this one out yet.
    gnubslayer, Jun 1, 2007
    #2
    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. Simon Storr
    Replies:
    5
    Views:
    39,307
  2. =?Utf-8?B?VG1hamFyb3Y=?=

    Can you refresh a form displayed via showmodaldialog method

    =?Utf-8?B?VG1hamFyb3Y=?=, Jun 17, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    5,047
    =?Utf-8?B?VG1hamFyb3Y=?=
    Jun 20, 2005
  3. =?Utf-8?B?VG1hamFyb3Y=?=

    Can you refresh a form displayed via showmodaldialog method

    =?Utf-8?B?VG1hamFyb3Y=?=, Jun 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    441
    Scolja
    Jun 20, 2005
  4. Replies:
    0
    Views:
    626
  5. Jonathan
    Replies:
    0
    Views:
    181
    Jonathan
    Jul 19, 2004
Loading...

Share This Page