?
Solved

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

Posted on 2010-09-13
8
Medium Priority
?
942 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 750 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

800 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