Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually in my master page i am displaying three div with different maters in that master page defaultly one div tag will be displayed and onother two div tags will be display none...it is working properly only. when i go to content page i want to display second div and rest of the divs should be display none is it possible. through .cs page

i am applying like finding the master page control in content page and making visible false but it is not working...my doubt is in master page i am using display none in designing page. but in content page i am using visible false. will it works...
Posted
Updated 1-Oct-13 23:36pm
v2

1 solution

I dont know if my answer will fullfil your question but I am going to answer on what I have precieve.
First Add the following code to the header of your master page
JavaScript
<script type="text/javascript">
        function changeDisplay(id) {
            if (id == "One") {
                document.getElementById('DivOne').style.display = 'block';
                document.getElementById('DivTwo').style.display = 'none';
                document.getElementById('DivThree').style.display = 'none';
            }
            else if (id == "Two") {
                document.getElementById('DivOne').style.display = 'none';
                document.getElementById('DivTwo').style.display = 'block';
                document.getElementById('DivThree').style.display = 'none';
            }
            else if (id == "Three") {
                document.getElementById('DivOne').style.display = 'none';
                document.getElementById('DivTwo').style.display = 'none';
                document.getElementById('DivThree').style.display = 'block';
            }
        }
    </script></script>

Then these are three divs for demonstration. Add them in the body of your aspx page. I gave the dives different color so they could be easily judged.
HTML
<div id="DivOne" style="display: none; border: solid 1px #000000; height: 50px; width: 50px;<br mode=" hold=" />        background-color: Gray;">
    </div>
    <div id="DivTwo" style="display: none; border: solid 1px #000000; height: 50px; width: 50px;<br mode=" hold=" />        background-color: White;">
    </div>
    <div id="DivThree" style="display: none; border: solid 1px #000000; height: 50px;<br mode=" hold=" />        width: 50px; background-color: Navy;">
    </div>

Now you have to call the javascript function in the .cs file of your master page. Note that the mathod should be public as we will access it in child page later in this solution. Write the method as follows:
C#
public void changeDivDisplay(System.Web.UI.Control sender)
        {
            string script = string.Format("<script language="javascript" type="text/javascript">changeDisplay('{0}');</script>", sender.ID.ToString());
            ScriptManager.RegisterStartupScript(sender, sender.GetType(), "changeDisplay", script, false);
        }

Now add three buttons to the child page of the preceding master page:
ASP.NET
<asp:button runat="server" id="One" text="One" onclick="DivOne_Click" xmlns:asp="#unknown" />
    <asp:button runat="server" id="Two" text="Two" onclick="DivTwo_Click" xmlns:asp="#unknown" />
    <asp:button runat="server" id="Three" text="Three" xmlns:asp="#unknown">
        onclick="DivThree_Click" /></asp:button>

Following is the Very importent part of solution. Add the following line right after <%@Page %> Tag of the preceding child page.
ASP.NET
<%@ MasterType VirtualPath="Site.master" %>

Now you are going to play the actual game. Actually you are going to call the "changeDivDisplay" method of master page in child page's button click events. Add the following code to the code behind file of your child page
C#
protected void DivOne_Click(object sender, EventArgs e)
        {
            Master.changeDivDisplay(this.One);
        }

        protected void DivTwo_Click(object sender, EventArgs e)
        {
            Master.changeDivDisplay(this.Two);
        }

        protected void DivThree_Click(object sender, EventArgs e)
        {
            Master.changeDivDisplay(this.Three);
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900