积极答复者
未将对象引用设置到对象的实例。

问题
-
在FormView的Insert模板中增加了一个查询按钮,OnClientClick="return findso();"
function findso() { document.getElementById('<%= FormView1.Row.FindControl("SOTextBox").ClientID %>').value = "88"; return true; }
document.getElementById('<%= FormView1.Row.FindControl("SOTextBox").ClientID %>').value = "88";
这一处,未将对象引用设置到对象的实例。
都已经执行过了,为什么还会在这个位置出错?- 已编辑 voodooer 2009年12月30日 2:25
答案
-
你好!这种情况是对的,Asp.Net 的机制就是这样的。你可以使用下面的方式避免这样的问题。在 FormView 绑定完成后,在客户端声明控件的 clientIdprotected void FormView1_DataBound(object sender, EventArgs e){TextBox control = this.EmployeeFormView.FindControl("SOTextBox") as TextBox;this.ClientScript.RegisterStartupScript(this.GetType(), "varField", String.Format("var clientId = '{0}'", (control == null) ? String.Empty : control.ClientID), true);}对应的客户端代码修改为function findso(){if (clientId != '')document.getElementById(clientId).value = '88';return false;}或者给按钮注册使用服务代码,判断控件是否存在后再确定是否赋值。
知识改变命运,奋斗成就人生!- 已标记为答案 voodooer 2009年12月30日 3:12
全部回复
-
你这样试试
你把你的FormView1也转换成客户端ID
("<%=FormView1.ClientID%>"))
http://blog.csdn.net/lxl_sports/archive/2009/08/17/4455681.aspx
努力+方法=成功 -
你这样试试
你把你的FormView1也转换成客户端ID
("<%=FormView1.ClientID%>"))
http://blog.csdn.net/lxl_sports/archive/2009/08/17/4455681.aspx
努力+方法=成功
谢谢您的回复!
如果把FormView1也转换成客户端ID,
我不知道这段代码应该怎么写,
document.getElementById('<%= FormView1.Row.FindControl("SOTextBox").ClientID %>').value = "88"; -
你好!这种情况是对的,Asp.Net 的机制就是这样的。你可以使用下面的方式避免这样的问题。在 FormView 绑定完成后,在客户端声明控件的 clientIdprotected void FormView1_DataBound(object sender, EventArgs e){TextBox control = this.EmployeeFormView.FindControl("SOTextBox") as TextBox;this.ClientScript.RegisterStartupScript(this.GetType(), "varField", String.Format("var clientId = '{0}'", (control == null) ? String.Empty : control.ClientID), true);}对应的客户端代码修改为function findso(){if (clientId != '')document.getElementById(clientId).value = '88';return false;}或者给按钮注册使用服务代码,判断控件是否存在后再确定是否赋值。
知识改变命运,奋斗成就人生!- 已标记为答案 voodooer 2009年12月30日 3:12
-
你好!
非常感谢你,按照你的方法做,问题解决了!我也明白是怎么回事了,提交页面时,脚本中有类似这种情况是对的,Asp.Net 的机制就是这样的。你可以使用下面的方式避免这样的问题。在 FormView 绑定完成后,在客户端声明控件的 clientIdprotected void FormView1_DataBound(object sender, EventArgs e){TextBox control = this.EmployeeFormView.FindControl("SOTextBox") as TextBox;this.ClientScript.RegisterStartupScript(this.GetType(), "varField", String.Format("var clientId = '{0}'", (control == null) ? String.Empty : control.ClientID), true);}对应的客户端代码修改为function findso(){if (clientId != '')document.getElementById(clientId).value = '88';return false;}或者给按钮注册使用服务代码,判断控件是否存在后再确定是否赋值。
知识改变命运,奋斗成就人生!
document.getElementById('<%= FormView1.Row.FindControl("SOTextBox").ClientID %>').value
这样的代码,都会报错!