在写这个程序的时候,在各个TabStrip控件中切换,发现当从精华区回到讨论区的时候,MultiPage中用户控件的boardID无法保持的问题.也就是boardID值丢失了.初始化成了原始值,而不是当前选择版快的值.
各个MultiPage中都有一个用户控件.在MultiPage中切换,也就意味着在各个用户控件中切换. 如何把当前的boardID值保存起来呢.从而恢复讨论区的视图.
我是这样来实现的: TabStrip是一个用户控件.里面包含MultiPage页,每个MultiPage中都再各包含一个BBS_List用户控件. 保持boardID的代码主要些在MultiPage中的BBS_List用户控件里的属性里. 如下:
#region 公共属性定义 public string BoardID { get{ return this.boardID ; } set { this.boardID = value ; //在这里保留boardID当前值 HttpCookie myCookie = new HttpCookie("boardID",value); Page.Response.Cookies.Add( myCookie ) ; } }
public string RootID { get{ return this.rootID ; } set{ this.rootID = value ; } }
TabStrip用户控件代码如下,给BBS_List传属性值 private void SetBBS_List() { myBBS_List.BoardID = this.boardID ; myBBS_List.Username = this.username ; myBBS_List.RootID = this.rootID ; myBBS_List.ParentID = this.parentID ; myBBS_List.IsCool = this.isCool ;
}
显示BBS列表的页包含了TabStrip用户控件.主要给TabStrip传入参数,代码如下: . . .
else { Message( "Disp/Default.aspx已经不是第一次Load了,REQUEST_METHOD=Post模式" , 0 ); if ( Request.Form[myDES.Encrypt( "username" , myDESKey )] == null ) { username_Param = myDES.Encrypt( "all" , myDESKey ); } else { username_Param = Request.Form[myDES.Encrypt( "username" , myDESKey )].ToString() ; } if ( Request.Form[myDES.Encrypt( "boardID" , myDESKey )] == null ) { boardID_Param = myDES.Encrypt( Page.Request.Cookies.Get("boardID").Value , myDESKey ); } else { boardID_Param = Request.Form[myDES.Encrypt( "boardID" , myDESKey )].ToString() ;
}
if ( Request.Form[myDES.Encrypt( "rootID" , myDESKey )] == null ) { rootID_Param = myDES.Encrypt( "0" , myDESKey ); } else . . . . myTabStrip.Username = myDES.Decrypt( username_Param , myDESKey ) ; myTabStrip.BoardID = myDES.Decrypt( boardID_Param , myDESKey ) ;
myTabStrip.RootID = myDES.Decrypt( rootID_Param , myDESKey ) ; myTabStrip.ParentID = myDES.Decrypt( parentID_Param , myDESKey ) ;
.................. ...................
到此,在各个用户控件之间切换,boardID的值就保留了!

|