標籤:
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>
c#伺服器端控制項confirm