Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Master / Child pages

Posted on 2012-03-29
8
Medium Priority
?
610 Views
Last Modified: 2012-03-30
I have a master / child page.  I have a button on the child page.   onClick, it calls a javascript function within the master page.   Is there a way to tie the button on the child page to a button on the master page, so that when the button on the  child page is clicked, it in turn clicks the button on the master page, which in turn would then call the javascript?

I have over 100 child pages, and I'm trying to avoid adding onClick code for every page, and instead have button on the child page automatically tied to a button on the master page
0
Comment
Question by:HLRosenberger
[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
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37783756
yes you can do it easily with jquery. Add the button on every client page and then add small jquery code to bind the click event authomatically which in turn call the master page button.

Suppose you have button on the each client page like below

<input type="text" id="butClient">Click Me Child</input>

Now on master page  there is a button with the following defination
<input type="text" id="butMaster">Click Me  Master</input>

Now simple add the code on the head section of  your Master page to bind the event and initiate the master's button click

$(function()  {
   $("#butClient").click(function() {
          $("#butMaster").click();
   });
});

Hope you get the idea of doing that.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 37783813
I have never used jquery.  Do I have to download a package?  Do most browsers support it?
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37783936
yes jquery is now supported by many broser like
IE 6.0+, FF 3.6+, Safari 5.0+, Opera, Chrome

For using jquery you can simple use by pasting the following code to in the head section of  your html.


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 1

Author Comment

by:HLRosenberger
ID: 37784028
Thanks.  How about passing parms on the click?
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37784105
please elaborate your needs in a more detail view.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 37784245
well, what I ultimately want to do is this:  Each child page contains a list of records from a database table.   Each child page is a different table.  I have about 100 child pages, and more to come.   I'm trying to get around adding code behind the buttons on each child page.   I want to pass an integer - primary key - and a string - table name - to Javascript code on the master page.  The  Javascript code uses showModalDialog to open page that allows edit of the database record, using a naming convention that incorporates the table name to generate the URL, and the integer is the record's primary key which is passed as a parm on the URL.

Make sense?
0
 
LVL 21

Accepted Solution

by:
masterpass earned 2000 total points
ID: 37785224
While Jquery is a viable option, Have a look here

http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx .. This will give you a better overview of how to find a control in masterpage from the childpage. In your case, find the button control in the masterpage and get the client ID of the button.

then in the child page load, all you have to do is

btnChild.Attributes.Add("onlick", "javascript to imitate the buttonclick from masterpage and you have the ID of the masterpage button");


hope this helps!
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 37786936
Thanks
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 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