Parent asp.net web page
This is the parent page. Clicking the link will open the child page Child.aspx in a new window. If you wish you can Open the new window in asp.net web page in different ways, which I have already discussed in a previous post.
Child asp.net web page
protected void btnOk_Click(object sender, EventArgs e) { //Implement Your logic here..... //.............................. //now refresh parent page and close this window string script = "this.window.opener.location=this.window.opener.location;this.window.close();"; if (!ClientScript.IsClientScriptBlockRegistered("REFRESH_PARENT")) ClientScript.RegisterClientScriptBlock(typeof(string), "REFRESH_PARENT", script, true); }In the child page, I have just put a button. When the button is clicked, the page logic will be implemented (which I have indicated by the comment lines in the event handler of the button in the asp.net child page).
The asp.net plus javascript logic
I have just created the javascript stuff that refreshes the parent page of this child page; see the lines:
this.window.opener.location=this.window.opener.location;this.window.close();
This line replaces the url of the parent page with its own url - that causes the parent page to reload. And yes, I have registered the javascript code block with ClientScript so that it is executed when the postback life cycle of this child page completes.
Happy programming!
12 comments:
thanks !
OMG! what a relief..thank you so much for this very helpful post...this is so easy to follow and the perfect solution ive been looking for...
you're a GENIUS!!!!! :)
-maria-
The post is too good. I was waiting for this code since long.
-SBLal
WOW!! Thank you very much
thanq so much......it saved my tym..!!the post is too good n well xplained..
the post is toooo good, saved so much time
what if i have to just refresh a control e.g gridview on parent page?
To refresh a gridview, you can put the gridview within an update panel. You can easily refresh the gridview control only by partially updating the updatepanel.
thanks you sir!
SUPERB!!! Exactly what I was looking for.
Thanks a lot.
Excellent and thank you so much... I was looking for this for quite some time. You're great!
Not working in IE8...plz help?
Post a Comment
Hope you liked this post. You can leave your message or you can put your valuable suggestions on this post here. Thanks for the sharing and cooperation!