访问母版页代码内部的内容页控件吗? [英] Access Content Page controls in inside of Master Page CodeBehind?

查看:54
本文介绍了访问母版页代码内部的内容页控件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个母版页和许多内容页.

在该内容页面中,我有一个DropDownList框.

我必须像这样
访问MasterPage内部的DropDownList控件

Hi to all,

I have one Master Page and many number of Content page.

With in that Content pages I have the DropDownList box.

I have to access the DropDownList Control inside of the MasterPage like this

protected void Page_Load(object sender, EventArgs e)
 {

ContentPlaceHolder ct = (ContentPlaceHolder)Master.FindControl(sender.ToString());
        ControlCollection CCl = ct.Controls;
        
        foreach (Control ctrl in CCl)
        {
            if (this.Controls.GetType() == typeof(DropDownList))
            {
                strDropDownID = ((DropDownList)ctrl).ID;
                if ((strDropDownID.Contains("ddlCountry")) || (strDropDownID.Contains("ddlFromCountry")) || (strDropDownID.Contains("ddlToCountry")) || (strDropDownID.Contains("ddlOrginCountry")) || (strDropDownID.Contains("ddlDestinationCountry")))
                {
                    ClientScriptManager cs = Page.ClientScript;

                    // Check to see if the client script is already registered.

                    if (!cs.IsClientScriptBlockRegistered(this.GetType(), "DropDownListScript"))
                    {

                        StringBuilder cstext2 = new StringBuilder();

                        cstext2.Append("<script type=''text/javascript''> function SelectCountry(''" + strDropDownID + "'') {");

                        cstext2.Append("script>");

                        cs.RegisterClientScriptBlock(this.GetType(), "DropDownListScript", cstext2.ToString(), false);

                    }
                }
            }

        }
}




代码的第一行获取内容页面名称,但给出错误.

我不知道如何获取当前页面的页面名称,该页面称为主页面.

如果您知道在母版页中访问页面名称的解决方案
这对我很有帮助.

感谢所有人.




The first line of the code gets Content page name but it gives an Error.

I dont know how to get the Page name of the Current Page which one is calling the Master Page.

If you know the solution to access the page name inside the master page
it would help me very much.

Thanks to all.

推荐答案

尝试本文

http://odetocode.com/articles/450.aspx [
Try this article

http://odetocode.com/articles/450.aspx[^]


这篇关于访问母版页代码内部的内容页控件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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