zoukankan      html  css  js  c++  java
  • 两个母板页嵌套,在内容页获得第一个母板页数据的问题

    问题参考http://topic.csdn.net/u/20111129/09/887007d1-566c-4205-85bd-063ff3b50f5d.html?seed=632864658&r=76705307#r_76705307,来自论坛网友问及:

    解决,避免使用FindControl方法,改用接口interface.

    IGetTextBoxValueable
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    /// <summary>
    /// Summary description for IGetTextBoxValueable
    /// </summary>
    namespace Insus.NET
    {
        public interface IGetTextBoxValueable
        {
            string GetTextBoxValue();
        }
    }

    在第一个MasterPage M1.master.cs实现这个接口:

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Insus.NET;

    public partial class M1 : System.Web.UI.MasterPage,IGetTextBoxValueable
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

       
        public string GetTextBoxValue()
        {
            return this.txtName.Text;
        }
    }

    最后是有内容页,把第一个MasterPage的M1转为接口,因为它有实作接口:

    View Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Insus.NET;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            IGetTextBoxValueable obj = (IGetTextBoxValueable)this.Master.Master;
            this.Label1.Text = obj.GetTextBoxValue();
        }
    }

     效果:

    测试代码:http://download.cnblogs.com/insus/ASPDOTNET/GetMasterPageControlValue.rar

  • 相关阅读:
    使用rem,动态设置root font size
    手机陀螺仪
    获取图片
    插件整理
    jquery图片懒加载
    关于underscore.js
    PCA
    Endnote9
    实验问题记录
    DN/TOA/SR
  • 原文地址:https://www.cnblogs.com/insus/p/2267322.html
Copyright © 2011-2022 走看看