1>服务器端控件删除的数据的时候,可以调用js的confirm防止误操作,但是默认的样式实在是让人难以接受,怎么调用自定义的提示框而且同步回发到服务器端,
服务器端的控件的用linkbutton,代码如下
<asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" OnClientClick="return jConfirm(this);" /> <script type="text/javascript"> function jConfirm(b) { if (confirm(‘是否删除‘)) { var href = $(b).attr("href"); eval(href); } //最后一句必须return false否则会提交 return false; } </script>
服务端有回发事件,页面加载后会自动生成__doPostBack(eventTarget, eventArgument)代码,eval执行实际上是_doPostBack函数。
<a onclick="return jConfirm(this);" id="CPHbody_ListView1_DeleteButton_1" href="javascript:__doPostBack('ctl00$CPHbody$ListView1$ctrl1$DeleteButton','')">删除</a> <script type="text/javascript"> //<![CDATA[ var theForm = document.forms[‘form1‘]; if (!theForm) { theForm = document.form1; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script>
时间: 2024-12-29 07:33:42