Solved

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

Posted on 2010-09-13
8
807 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now