By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Forcing postback on a web dialogs opening window

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Nov 19 '05 #2

P: n/a
Here is also a blog post and a sample covering this technique
http://blogs.aspadvice.com/joteke/ar...6/15/4063.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Nov 19 '05 #3

P: n/a
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;}"

"SkeanDu" wrote:
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

Nov 19 '05 #4

P: n/a
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!!

Nov 19 '05 #5

P: n/a
John where are your server controls located? I couldn't see them on
GotDotNet.

Nov 19 '05 #6

P: n/a
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
Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.