关于控件postback 后viewstate加载失败的问题

我写了一个控件Inherits TextBox,里面有一个复杂属性Tip,但每次postback的时候都说加载viewstate失败,除非我在!postback的情况下给Tip.xxx赋值.

下面我贴出代码,我已经搞了一天了,搞不出什么原因。


JTextBox控件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Madou.WebControls
{
    [DefaultProperty(
"Text")]
    [ParseChildren(
true), PersistChildren(false)]
    [ToolboxData(
"<{0}:JTextBox runat=server></{0}:JTextBox>")]
    
public class JTextBox : System.Web.UI.WebControls.TextBox
    
{

        
public JTextBox()
        
{
            BackColor 
= System.Drawing.Color.Beige;
           
        }


        
"Private"

        
"定义属性"

        
"override"
    }

}

Tip属性类
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Madou.WebControls.Converter;
namespace Madou.WebControls
{
    [TypeConverter(
typeof(ClipTipComponentConverter))]
    
public class ClipTipComponent : IStateManager
    
{
        
"Private"

        
public ClipTipComponent() { }

        
"属性"

        
"HELP

        
"重写的方法"

        
IStateManager Members

        

        
internal void SetDirty()
        
{
            _viewState.SetDirty(
true);
        }


       
internal void RegisterJs(Control target, string clientId)
        
{
            
if (target is WebControl)
            
{
                
string tooltip = (target as WebControl).ToolTip;
                
if (string.IsNullOrEmpty(tooltip.Trim()))
                
{
                    
if (!EnabledAjax)
                        
return;
                }


            }

           
            
if (EnabledClipTip)
            
{
                JavaScriptWriter w 
= new JavaScriptWriter();
                w.AddLine(
"$(function()");

                w.OpenBlock();
                
if (!EnabledAjax)
                
{
                    
if (string.IsNullOrEmpty(SplitTitle))
                        SplitTitle 
= "|";
                    w.AddLine(
"$('#" + clientId + "').cluetip({splitTitle: '" + SplitTitle + "'");
                }

                
else
                
{
                    w.AddLine(
"$('#" + clientId + "').cluetip({splitTitle: ''");
                }

                w.AddJSONItem(
"cluetipClass", ClueTipClass);
                w.AddJSONItem(
"hoverClass", HoverClass);
                w.AddJSONItem(
"arrows", Arrows);
                w.AddJSONItem(
"dropShadow", DropShadow);
                w.AddJSONItem(
"dropShadowSteps", DropShadowSteps);
                w.AddJSONItem(
"sticky", Sticky);
                w.AddJSONItem(
"mouseOutClose", MouseOutClose);
                w.AddJSONItem(
"activation", Activation);
                w.AddJSONItem(
"clickThrough", ClickThrough);
                w.AddJSONItem(
"tracking", Tracking);
                w.AddJSONItem(
"delayedClose", DelaydClose);
                w.AddJSONItem(
"closePosition", ClosePosition);
                w.AddJSONItem(
"width", TipWidth);
                w.AddJSONItem(
"height", TipHeigth);
                w.AddJSONItem(
"closeText", CloseText);
                w.AddJSONItem(
"truncate", Truncate);

                w.AddLine(
"});");
                w.CloseBlock();
                w.AddLine(
");");

                target.Page.ClientScript.RegisterClientScriptBlock(target.GetType(), clientId, w.ToString(), 
false);
            }

        }


      
internal void RegisterJs(Control target)
        
{
            
string clientId = target.ClientID;
            RegisterJs(target, clientId);
        }

    }

}



出现的问题,一定要在!PostBack给Tip.xxx赋值,否则出现viewstate不能正常加载的错误提示(如果给JTextBox的Text赋值的话),请问这个是什么原因
bug已经发现,原来System.Web.UI.WebControls.TextBox的SaveViewState()已经是Pair
posted @ 2008-02-03 12:54  永不言败  阅读(639)  评论(1编辑  收藏  举报