Solved

Master / Child pages

Posted on 2012-03-29
8
594 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
  • 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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 37784028
Thanks.  How about passing parms on the click?
0
Highfive Gives IT Their Time Back

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now