参看网上一个方法,在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都会消失了.想问问各位高手,那个重写的方法到底是怎么影响的呀??
{
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都会消失了.想问问各位高手,那个重写的方法到底是怎么影响的呀??
解决方案 »
- 关于sharepoint去除左边导航栏后,添加通知报错
- ASP.NET的运行机制
- 郁闷
- asp.net客户端小问题
- 朋友们介绍本关于模块设计开发的书像:新闻系统,下载系统,影视....等等
- WebForm是否在运行时可以动态改变POST的URL?
- Calender控件?
- 如何在C#.NET中打开并运行一个客户端的应用程序?
- 关于清除Session后的页面刷新问题。
- 我的.aspx的网页为什么无法显示?
- User Control如何在Design View里设DataSource属性?
- 新年的第一个贴子,来者有分,VS2005的一个困惑,怎样把.sln生成在项目文件夹里(即工程源代码同一个文件夹里)
不过你的问题应该还是页面生存周期的问题.
你好好跟踪下, 控件生成, 装载数据的过程.
我估计是因为页面重新加载过了. 而数据没有重新装载.
// so that the active control has a difference appearance
if(!ispostback)
{
Helpers.SetInputControlsHighlight(this, "highlight", false);
base.OnLoad(e);
}