参看网上一个方法,在BasePage里面重写Page_OnLoad,用来使获得焦点的文本框高亮,代码如下public class BasePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            // add onfocus and onblur javascripts to all input controls on the forum,
            // so that the active control has a difference appearance
            Helpers.SetInputControlsHighlight(this, "highlight", false);
            base.OnLoad(e);
        }
public static void SetInputControlsHighlight(Control container, string className, bool onlyTextBoxes)
        {
            foreach (Control ctl in container.Controls)
            {
                if ((onlyTextBoxes && ctl is TextBox) || ctl is TextBox || ctl is DropDownList ||
                    ctl is ListBox || ctl is CheckBox || ctl is RadioButton ||
                    ctl is RadioButtonList || ctl is CheckBoxList)
                {
                    WebControl wctl = ctl as WebControl;
                    wctl.Attributes.Add("onfocus", string.Format("this.className = '{0}';", className));
                    wctl.Attributes.Add("onblur", "this.className = '';");
                }
                else
                {
                    if (ctl.Controls.Count > 0)
                        SetInputControlsHighlight(ctl, className, onlyTextBoxes);
                }
            }
        }
    }
可是我在自己用的时候不小心重写了基类Page_OnInit(),随后发现在页面里面的所有detailsview+objdatasource的组合都出现问题了,每次插入和更新数据时,detailsview都会消失了.想问问各位高手,那个重写的方法到底是怎么影响的呀??

解决方案 »

  1.   

    如果是VS2005 最好用母版页取代这种方法.没用过detailsview, 很少用微软封装的东西.
    不过你的问题应该还是页面生存周期的问题.
    你好好跟踪下, 控件生成, 装载数据的过程.
    我估计是因为页面重新加载过了. 而数据没有重新装载.
      

  2.   

    删除对Page_OnInit()的重载不就可以了吗
      

  3.   

    // add onfocus and onblur javascripts to all input controls on the forum,
                // so that the active control has a difference appearance
    if(!ispostback)
    {
                Helpers.SetInputControlsHighlight(this, "highlight", false);
                base.OnLoad(e);
    }