Solved

How to call parent page button event from popup window or child page.

Posted on 2010-09-13
8
844 Views
Last Modified: 2012-05-10
hi,
i have a event in parent.aspx. named savedata.
when i click on save data a popup  should be opened.
In popup window(popup.aspx there is a event called Close.
in that close event ineed to call the parentpage's savedata event.
pls giveme the code for the above scinnario
With Regards
Ravi
0
Comment
Question by:mu_ravi1
8 Comments
 
LVL 21

Expert Comment

by:chapmanjw
ID: 33664642
0
 
LVL 5

Expert Comment

by:milindsaraswala
ID: 33664674
hi Ravi
every page in asp.net is a class. so from Page 2, you can use the following
code:

dim myPage1 as new Page1()
myPage1.FunctionWhatever()

you must understand though that you would just be creating a page object
with a scope/lifetime limited to the current block of code you are in (e.g.
Page2.button_ok_click).

what you should really do in your situation is organise your code better.
if you have shared code that is needed by Page1 and Page2 then it should be
in a class of its own. if you're using .Net2, just put a new class file
into App_Code which is the shared code folder. otherwise just insert a new
class anywhere in the application, then it can be used by any page in your
site, without having to go creating Page objects just to use the code
contained in them. the code i've written above is a really poor way of
sharing code between pages, unless it is absolutely necessary, and even then
i can't think of a good reason why you would want to do this. just suppose
that later on in the development of your site, you decide to delete Page1,
but ooops you forgot you had code in there that Page2 is dependent on, so
you break the site and have to pull out the code.

a page should be encapsulated, without having dependencies on other pages.
otherwise you will end up with a monster of a web site with so many
inter-dependencies between pages that it will be very difficult to maintain.

Milind
0
 
LVL 9

Expert Comment

by:abhinayp86
ID: 33666240
Yup... here is the code.


VB or C#?

I put C# version here.

btnSave is the ID of ur Parent save button
In the aspx of the child page (head), put this

  <script type ="text/javascript" language="javascript" > 
function callParentClick() {
       window.opener.document.getElementById('<%=btnSave.ClientID%>').click();
      }
</script>

------------------------

In the button click event of the close button(code behind .cs file) put this

 ClientScript.RegisterStartupScript(this.GetType(), "CallParent", "callParentClick();", true);

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:mu_ravi1
ID: 33670296
Hi all,

My question is for using delegates or event handling.

i have a event in parent.aspx. named savedata.
when i click on savedata Button a popup  should be opened.
In popup window(popup.aspx there is a event called with CloseButton.
in that close event i need to call the parentpage's savedata Button event.
pls giveme the code for the above scinnario
Regards
ravi
0
 
LVL 3

Expert Comment

by:vusov
ID: 33671382
Does your popup is called from server side? If yes you dont need to call  savedata Button event. You should store all data in the session and then read it on the popup CloseButton click.
//parent page
private void SavedataButton_OnClick()
{
   Session["Data"] = ....
}

//popup page

private void CloseButton_OnClick()
{
   object data = Session["Data"];
}

Open in new window

0
 
LVL 9

Accepted Solution

by:
abhinayp86 earned 250 total points
ID: 33672877
@ravi.
My code does the exact same thing u r askin for.
0
 

Author Closing Comment

by:mu_ravi1
ID: 33679561
I used the concept and implemented differentely
0
 
LVL 9

Expert Comment

by:abhinayp86
ID: 33681539
No probs :)
All that matters is you found ur answer.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question