页面中.... pageload()
{
    ....
   viewstate["proid"]=dr["proid"].tostring();
.....}usercontrol 中....pageload()
{
   int proid=viewstate["proid"].tostring();  报错,提示为null
}我百度了下,了解到用户控件里面不能直接访问页面viewstate值道理我已经知道,现在想要个代码,我不是拿来直接用的,我肯定还要学习,所以不必说我是伸手党。60分,第一个能解决这个问题的就给他了。谢谢大家!其实新手有很多东西要学习,但是目前只能一边工作一边学习再次感谢!

解决方案 »

  1.   

    改Session或是在userControl写一个方法。在页面传值给这个方法即可。
      

  2.   

    在 page 中定义属性 返回对 viewstate的引用usercontrol 中将 page 对象 转换成对应的类型然后访问属性即可
      

  3.   

    写在页面里
    public string Vproid 
    {
        set {  ViewState["proid"]=value;}
        get {  return (ViewState["proid"]??"").ToString();}
    }------------------
    usercontrol 中  PageName 就是你页面的名称PageName page= this.Page as PageName;
    if(page!=null)
    {
        page.Vproid  返回的就是你需要的了
    }
      

  4.   

    页面中.... pageload()
    {
      ....
      Session["proid"]=dr["proid"].tostring();
    .....}usercontrol 中....pageload()
    {
      int proid=Session["proid"].tostring(); }把ViewState改为Session即可