母版页中div标签面临的问题 [英] Problem facing on div tag in master page

查看:68
本文介绍了母版页中div标签面临的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上在我的母版页面中,我在该母版页中显示三个具有不同母版的div,默认情况下将显示一个div标签,另外两个div标签将不显示...它只能正常工作。当我去内容页面时,我想显示第二个div,其余的div应显示无可能。通过.cs页面



i应用如在内容页面中查找母版页控件并使其显示为false但它不起作用...我怀疑是在母版页中我在设计页面时使用display none。但在内容页面我使用可见的假。它会起作用...

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

推荐答案

我不知道我的答案是否会满足你的问题,但我会回答我已经解决的问题。

首先将以下代码添加到母版页的标题中

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



然后这三个div用于演示。将它们添加到aspx页面的正文中。我给了潜水不同的颜色,以便轻松判断。


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.

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



现在您必须致电您的母版页的.cs文件中的javascript函数。请注意,mathod应该是公共的,因为我们将在本解决方案的后面的子页面中访问它。编写方法如下:


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:

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



以下是解决方案的非常重要的部分。在<%@ Page%>之后添加以下行上一个子页面的标记。


Following is the Very importent part of solution. Add the following line right after <%@Page %> Tag of the preceding child page.

<%@ MasterType VirtualPath="Site.master" %>



现在你将玩实际游戏。实际上,您将在子页面的按钮单击事件中调用母版页的changeDivDisplay方法。将以下代码添加到子页面的代码隐藏文件中


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

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);
        }


这篇关于母版页中div标签面临的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆