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的值都是空值.是不是每次回发都首先重新刷新了控件树,所以得到的就是空值?这个问题该怎么解决呢?谢谢
if(tb!=null)
if(tb.Text.ToString().Trim()!="")
pageIndex=Convert.ToInt32(tb.Text.ToString().Trim());
pageIndex是一个属性,this.ClientID是该组合控件的客户端ID,gotoPage是那个TextBox的ID.我每次回发过后,取得的TextBox的值都是空值.是不是每次回发都首先重新刷新了控件树,所以得到的就是空值?这个问题该怎么解决呢?谢谢
{
中赋值
}
得到是空?可是你做了!=null的判断,
那么是没找到控件,还是没取到值哪??
你吧!=null去了,这样如果没找到就会出现"未将对象引用到实例"的错误,
那么说明你findcontrol有问题.
如果上面没问题说明值被刷掉了
你做了这个,如果没找到下面是不会执行的
pageIndex=Convert.ToInt32(temp);终于实现了,但是安全性不是很好,不喜欢!希望有更好的方法
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);