我在利用Repeater数据绑定的时候,利用它的模板列添加了一个button控件.现在想给这个button添加一个button_click函数,手动添加的时候出现错误.我是这么做的:
1 写click函数
public void Button_Reply_Click(object sender, System.EventArgs e)
{
Response.Write("<script>alert('测试看看可以否')</script>");
}
2 在设计器代码中添加这么一句
this.Button_Reply.Click +=new System.EventHandler(this.Button_Reply_Click);错误提示:System.NullReferenceException: 未将对象引用设置到对象的实例
应该怎么解决那????????
1 写click函数
public void Button_Reply_Click(object sender, System.EventArgs e)
{
Response.Write("<script>alert('测试看看可以否')</script>");
}
2 在设计器代码中添加这么一句
this.Button_Reply.Click +=new System.EventHandler(this.Button_Reply_Click);错误提示:System.NullReferenceException: 未将对象引用设置到对象的实例
应该怎么解决那????????
解决方案 »
- 关于在使用vs2010插入代码段的一个小问题
- Sys.WebForms.PageRequestManagerParserErrorException: 未能分析从服务器收到的消息。
- 一个通用计数器的问题
- asp的进销存
- asp.net 读取EXCEL文件出现问题,
- 挺急的。regularexpressionvalidator控件怎么不能控制文本框中输入的是数值呢?请教大家啊。在线等
- 有关response的问题
- asp.net 调试出错,报不能锁定文件
- 关于用GRIDVIEW绑定后的代码进行优化的问题~在线等待!!祝大家国庆节快乐。。。。·_·~
- 新手问题:这样的SqL语句怎样写?
- 抽屉控件你在哪里
- 大家进来看看,一个很简单的问题,关于cookies的
Button_Reply.Attributes.Add("onclick", "alert('测试看看可以否');");
是添加客户端脚本
if(click!=null)
{
click(this,e);
}
Button_Reply.Attributes.Add("onclick", "alert('测试看看可以否');");
===
没看清楚
应该在Repeater数据绑定时,或绑定后添加
this.Button_Reply.Click +=new System.EventHandler(this.Button_Reply_Click);
这句执行的时候,Repeater里还没有东西,不存在Button_Reply
htmlinputbutton butok=(htmlinputbutton)e.item.findcontrol("ckball");//****调用事件处理机制
this.butOK_ServerClick += new System.EventHandler(this.butOK_ServerClick);private void butOk_ServerClick(object sender eventarges e)
{
//****代码
}
在获取了控件之后,利用如下方法
private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
System.Web.UI.WebControls.Button x = (Button)e.Item.FindControl("LinkButton_Reply");
}
然后在哪个地方加"//****调用事件处理机制
this.butOK_ServerClick += new System.EventHandler(this.butOK_ServerClick);"这个东东
<itemtemplate>
<asp:label runat="server" /><asp:button id="btn1" runat="serve" onclick="btn1_click" />
</itemtemplate>
</asp:repeater>sub btn1_click(sender as object,e as eventargs)
'
end sub
{
Button_Reply.Attributes.Add("onclick", "alert('测试看看可以否');");
}