Avatar of mu_ravi1
mu_ravi1
 asked on

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

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
ASP.NET.NET Programming

Avatar of undefined
Last Comment
abhinayp86

8/22/2022 - Mon
chapmanjw

milindsaraswala

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
abhinayp86

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
mu_ravi1

ASKER
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
vusov

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

ASKER CERTIFIED SOLUTION
abhinayp86

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mu_ravi1

ASKER
I used the concept and implemented differentely
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
abhinayp86

No probs :)
All that matters is you found ur answer.