Friday, November 05, 2004

Calling doPostBack from a child window for example a popup

(Ejecutar doPostBack desde una ventana hija como por ejemplo un popup)

In web applications you often open a popup with any data which fill some field in the opener window.

For example if you have a field that could have different data depending on the values that you have selected in other fields, you normally will not want to load this data when the page will be loaded. Instead of this, when you are going to fill this field, you open a popup, given it the values of the other fields, and when you select something into the popup you fill the field in the opener and close the popup.

See an example:

I have a textbox named TextBox1 which going to be filled by a link into a popup created using window.open()

In the popup I put the following code:

<a href="#" onclick="window.opener.document.getElementById('TextBox1').value='Filled From Popup';window.opener.__doPostBack('TextBox1','');window.close();">doPostBack and close</a>

When you click in the link you can see that the textbox will be filled with the text Filled From Popup, the doPostBack will be executed, and the popup will be closed.

One reminder: If ASP.Net doesn't create the javascript code for __doPostBack in the opener window, you can force it. See this post


Permalink: Calling doPostBack from a child window for example a popup 

2 Comments:

At 1:16 PM, Blogger Unknown said...

Thanks a lot Jose.. Your example really worked for me - Ramesh

 
At 8:40 AM, Anonymous Anonymous said...

Very nice. Thank You..

 

Post a Comment

<< Home