Solved

Master / Child pages

Posted on 2012-03-29
8
608 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

617 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