try
Control c = Page.FindControl(YourControl字符串);

解决方案 »

  1.   

    To  saucer(思归, MS .NET MVP),
      问题是如果不存在你想要找的控件,页面就会返回错误。
      

  2.   

    Control c = Page.FindControl(YourControl字符串);
    if (c == null)
    {
    //does not exist
    }
    else
    {
    //exist
    }
      

  3.   

    saucer(思归, MS .NET MVP) 说的那是查找控件,楼上说的好象是要把字符串值转换成控件,如果是的话可以这样子:
    Control mycontrol=new LiteralControl("我的字符串近件!");
      

  4.   

    在思归所写的代码中,当不存在“YourControl字符串”这样的控件时,“Page.FindControl(YourControl字符串)”就会返回错误,也就是说根本不会执行下面的语句了,思归难道没有考虑到这一点吗?
      

  5.   

    这么说吧,我现在只知道一个可能存在的控件的名字objCtl,而我又想用Page.Controls.Contains(Control c)来判断是否存在这样的控件,注意这里的Contains接收的是一个Control类型的参数,那么,这里如何将objCtl转换成Control?
      

  6.   

    try{
    Control c = Page.FindControl("objCtl");
    //do sth here....
    }catch(){}
      

  7.   

    FindControl是不会抛出异常的。
      

  8.   

    To  volitant2002(Volitant) :
    你FindControl一个任意的字符串试试,看返回什么结果。