Force a postback for a page from a different frame

  • Thread starter Jeronimo Bertran
  • Start date
J

Jeronimo Bertran

I have a DataGrid that gets filled based on a filter which is defined by
the values that the user selects on several controls. When the page
postbacks after changing the selection on the filter controls, the DataGrid
refreshes itslef. Now, I also need to refresh the DataGrid if I detect
that something "external" has changed (keeping the filter that the user is
using).

For this, I have created a page that partially refreshes itslef in order to
determine if a datagrid must be refreshed. I created a frame within my page

<iframe id='AutoRefresh' src='MonitorAutoRefresh.aspx></iframe>

where MonitorAutoRefresh includes a <meta http-equiv='refresh' content=" +
ResponseTime.ToString() + ">"

MonitorAutorRefresh Page_Load does the following:

// Check if the main grid needs to be refreshed
if (RefreshNeeded())
{
Page.RegisterStartupScript("RefreshParent", "<script
language='javascript'>\r\nRefreshParent()\r\n</script>\r\n");
}

and the script RefreshParent is defined as:

function RefreshParent()
{
window.parent.location.href = window.parent.location.href;
}


The problem I have is that since I am refreshing the parent, I am losing
the state information of the filter controls, and thus the grid gets
refreshed using the default values.

Can I force a postback on the main page to be generated from the
MonitorAutoRefresh panel instead of calling my RefreshParent (which would
preserve the values on the filter controls)? Or, do I need to store the
control values on a session variable in order to preserve them after
calling RefreshParent? Or is there a better solution to what I am trying to
do?

Thanks,

Jeronimo
 
B

Bruce Barker

do the a submit instead.

function RefreshParent()
{
window.parent.forms[0].submit();
}

-- bruce (sqwork.com)
 
J

Jeronimo Bertran

Thanks Bruce,

I get the following error :

window.parent.forms.0 is null or not an object.
 
S

Steven Cheng[MSFT]

Hi Jeronimo,

I think the statement Bruce means should be:

window.parent.document.forms[0].submit();

Also, if there're any submit button on the parent aspx page, we can
consider using the

document.getElementById(id) to reference the button element through id
and then call its click() method which can
simulate a submit button's click postback. In fact, sometimes we even put
such a hidden button( set width , height to 1) and use script to invoke its
click() function to do the samething.

Hope also helps.Thanks,


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top