TextBox tb=(TextBox)Page.FindControl(this.ClientID+":gotoPage");
if(tb!=null)
if(tb.Text.ToString().Trim()!="")
pageIndex=Convert.ToInt32(tb.Text.ToString().Trim());

pageIndex是一个属性,this.ClientID是该组合控件的客户端ID,gotoPage是那个TextBox的ID.我每次回发过后,取得的TextBox的值都是空值.是不是每次回发都首先重新刷新了控件树,所以得到的就是空值?这个问题该怎么解决呢?谢谢

解决方案 »

  1.   

    if(!IsPostBack)
    {
    中赋值
    }
    得到是空?可是你做了!=null的判断,
    那么是没找到控件,还是没取到值哪??
    你吧!=null去了,这样如果没找到就会出现"未将对象引用到实例"的错误,
    那么说明你findcontrol有问题.
    如果上面没问题说明值被刷掉了
      

  2.   

    (tb!=null)
    你做了这个,如果没找到下面是不会执行的
      

  3.   

    看你的代码好像在组合控件里面访问TextBox, 这样直接使用 TextBox 的ID号访问不就行了吗?
      

  4.   

    string temp=Page.Request.Form["CoolPager1:gotoPage"].ToString().Trim();
    pageIndex=Convert.ToInt32(temp);终于实现了,但是安全性不是很好,不喜欢!希望有更好的方法
      

  5.   

    如果没有关于控件是否存在和控件的值是否为空的验证将会出现下面的错误
    Server Error in '/Addr' Application.
    --------------------------------------------------------------------------------Input string was not in a correct format. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format.Source Error: 
    Line 461: default:
    Line 462: TextBox tb=(TextBox)Page.FindControl("CoolPager1:gotoPage");
    Line 463:     pageIndex=Convert.ToInt32(tb.Text);
    Line 464: //string temp=Page.Request.Form["CoolPager1:gotoPage"].ToString().Trim();
    Line 465: //pageIndex=Convert.ToInt32(temp);
     
      

  6.   

    为什么Request能得到那个值但用TextBox却得不到!好奇怪啊!!!!!!!!!!!!搞不清楚不睡觉!
      

  7.   

    你最好是得到组合控件一个引用,然后再用这个引用的FindControl方法来获取里面的控件,我不知道你说的组合控件是什么意思,偶没用过