Forcing postback on a web dialogs opening window

S

SkeanDu

Ok, here is my problem.

I have an aspx page that displays a databound datagrid and in one of
the datagrid column headers I have an image that when clicked opens up
a modal web dialog (another aspx page).
From this dialog I want the users to be able to select a filter item
from a databound combobox and click on the apply button on the web
dialog that will then disappear and the filtered data will be displayed
on my datagrid.

Now here is the problem: How can I force a postback on the original
aspx page containing the datagrid so that only the filtered data is
displayed? Basically I want to pass back the selected cobobox item from
the web dialog to the calling window and then use that data to filter
my dataset and rebind to the datagrid.

I've thought about using hidden input fields on the datagrid page and
populating them when the user clicks the apply button on the web
dialog. But how do I then fire a postback to rebind my datagrid? Is
there a way to fire the postback on the datagrid page when the user
clicks the apply button on the web dialog page? The way I'm going about
it just now involves mainly client side java script but I am sure there
must be a way to do this server side?

Anyway, if anyone has any pointers I would be very grateful.

Thanks,

Vincent
 
T

Teemu Keiski

Add a server-side Button control to the main page, set its Visible to false
and generate a javascript call with
Page.GetPostBackEventReference(the-button-as-argument-here).

That'll return you a __doPostBack call which is able to cause button click
effect when it is called at client-side. So extend the idea and create your
own js method and append the js call generated in previous step to it. So
that you can call it cross window from the popup and calling it causes the
postback.

So in essence effect is that when you call that from popup window
(opener.yourmethodname() if main page is the opener window and
yourmethodname() function has the call to __doPostback with the dummy button
as argument) it is as if __doPostBack is called for the hidden button and
you can actually run sensible logic in the main window and control that from
the popup.
 
G

Guest

I have to do this so often, I wrote a set of server controls to help. I've
uploaded them to GotDotNet, so in a few days you should be able to find them
there.

Assuming that you have added a client side handler for the click event to a
normal control (which is what I do in the library), the postback will occur
based on whether you return true or false from the onclick event. If you
return false, it will not postback. If you return true, it will postback.
An example:

'Building Client side window attributes with width and height.
'the the window will be positioned to the middle of the screen
windowAttribs = "dialogHeight:" & _dialogHeight & "px;" & _
"dialogWidth:" & _dialogWidth & "px;" & _
"left:'+((screen.width -" & _dialogWidth & ") /
2)+';" & _
"top:'+ (screen.height - " & _dialogHeight & ")
/ 2+';" & _
"edge:Sunken; status:0;" & _
"resizable:0;Help:No;"

'Building the client script- window.open, with additional
parameters
'having return true; at the end of this line is what allows the
web control's
'server side click event still fire
clientScript = "rsc_getObj(""" & Me.UniqueID &
"_DIALOGRETURNVALUE" & """).value=window.showModalDialog(""" & _pagePath &
""",""" & _windowName & """,""" & windowAttribs & """);if(rsc_getObj(""" &
Me.UniqueID & "_DIALOGRETURNVALUE" & """).value!=""0"" & rsc_getObj(""" &
Me.UniqueID & "_DIALOGRETURNVALUE" & """).value!=""undefined""){return
true;}else{return false;}"
 
S

SkeanDu

Thanks Teemu,

I followed the blog post and finally got the postback to happen from
the main page. Only problem is it doesn't complete the postback until
the modal web dialog is manually closed. I've tried closing it
programatically with 'self.close' and 'window.close' before and after
the the call to the doPastback function on the main page but it just
doesn't seem to want to close. When I break in the main page just
before the doPostBack is called I seem to have no visibility of the web
dialog although it is still displayed. I'm sure there is a simple
solution but I just can't see it!!
 
T

Teemu Keiski

Ah,

you use those *real* :) modal dialogs (window.showModalDialog etc), mine is
using just popup (which you can try to force to be on top though there's no
bullet-proof solution to that). I suppose that with them you first have to
complete the dialog before postback can happen (execution goes back to the
window that opened the dialog)

Teemu
 

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,813
Latest member
lawrwtwinkle111

Latest Threads

Top