一个控件(在同一页面)从另一控件中得到属性值

翻译|其它|编辑:郝浩|2007-10-17 14:59:16.000|阅读 868 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

public bool CheckUserCtrl()
  {
   try
   {
    System.Web.UI.Page p = this.Parent.Page;
    if(this.ControlID.Length == 0)
    {
     //控件是否存在
     return false;
    }

    System.Web.UI.UserControl uctrl = (System.Web.UI.UserControl)p.FindControl(ControlID); //通过给的属性(控件 ID)得到整个控件
    if(uctrl == null)
    {   
     return false;
    }

    Type objType = uctrl.GetType();

    #region  判断  RecordID 是否存在
    PropertyInfo idInfo = objType.GetProperty("RecordID");//到页面所调另一控件中得到属性值
    if(idInfo == null)
    {
     //RecordID(idInfo)属性是否存在
     return false;
    }
    object oRecordID = idInfo.GetValue(uctrl,null);  
    if(oRecordID == null || Convert.ToInt32(oRecordID) == 0)
    {
     //判断 oRecordID 是否为 null
     return false;
    }
    this.RecordID = Convert.ToInt32(oRecordID);
    #endregion

    #region 判断 RecordName 是否存在
    PropertyInfo explainInfo = objType.GetProperty("RecordName");
    if(explainInfo == null)
    {
     //判断 RecordName 是否存在
     return false;
    }
    object oExplain = explainInfo.GetValue(uctrl,null);
    if(oExplain == null || oExplain.ToString() == string.Empty)
    {
     //判断 oExplain(explainInfo)是否为 null
     return false;
    }
    this.Explain = oExplain.ToString();
    #endregion

    #region  判断 ModelName 是否存在
    PropertyInfo modelInfo = objType.GetProperty("ModelName");//到页面所调另一控件中得到属性值
    if(modelInfo == null)
    {
     //判断 ModelName 是否存在
     return false;
    }
    object oModelName = modelInfo.GetValue(uctrl,null);
    if(oModelName == null || oModelName.ToString() == string.Empty)
    {
     //判断 oModelName(ModelName)是否为 null
     return false;
    }
    this.ModelName = oModelName.ToString();
    #endregion

    return true;
   }
   catch(Exception ex)
   {
    return false;
   }
  }


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:csdn

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP