首页 新闻 会员 周边

asp.net按钮客户端事件使用jquery绑定后,刷新后事件丢失问题?

-1
悬赏园豆:10 [已解决问题] 解决于 2015-03-31 15:43

html页面:

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebSite.WebForm3" %>
 2 
 3 <!DOCTYPE html>
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 8     <title></title>
 9     <script src="Scripts/jquery-1.11.2/jquery-1.11.2.min.js"></script>
10     <script>
11         $(function () {
12             $("#btnOK").click(function () {
13                 alert("test");
14             });
15         });
16     </script>
17 </head>
18 <body>
19     <form id="form1" runat="server">
20         <asp:ScriptManager ID="ScriptManager1" runat="server">
21         </asp:ScriptManager>
22         <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
23             <ContentTemplate>
24                 <asp:Button ID="btnOK" runat="server" Text="测试" OnClick="btnOK_Click" />
25                 <asp:Label ID="labInfo" runat="server" Text=""></asp:Label>
26             </ContentTemplate>
27         </asp:UpdatePanel>
28     </form>
29 </body>
30 </html>

后台代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 namespace WebSite
 9 {
10     public partial class WebForm3 : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14 
15         }
16 
17         protected void btnOK_Click(object sender, EventArgs e)
18         {
19             this.labInfo.Text = DateTime.Now.ToString();
20 
21         }
22     }
23 }

第一次执行正常,先显示 对话框   test  的提示,

但是第二次点击就不弹出提示了。。有一种解决方法是在后台再次绑定事件,但这种方式较为繁索,而且不方便。。

相请问大家有没有什么简单的处理方法。

paaple的主页 paaple | 初学一级 | 园豆:15
提问于:2015-02-04 08:53
< >
分享
最佳答案
0

通过按钮的OnClientClick属性去执行javascript函数。

收获园豆:10
xiaocong_soft | 小虾三级 |园豆:556 | 2015-02-04 09:03

必须用jquery绑定,并不一定是 click,还有如其它控件。。。已经解决了,谢谢

paaple | 园豆:15 (初学一级) | 2015-02-04 09:05
其他回答(1)
0

问题已经解决。

paaple | 园豆:15 (初学一级) | 2015-02-04 09:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册