asp.net中,如何給按鈕增加JS事件

來源:互聯網
上載者:User

在表單中,有個按鈕,是用來添加使用的,在該按鈕的自身protected void add_button_Click(object sender, EventArgs e)裡面實現將資料添加到資料庫的,但是,同時,我希望點擊該按鈕,能對form進行js表單檢驗,不知道該怎麼實現,我試過在page_load中為該按鈕添加一個onclick時間,觸發一個js指令碼,但這樣的話,點擊按鈕,就不能進行添加操作了,我該怎麼辦?

 

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="Button1_Click" OnClientClick="javascript:return user_see()">查看</asp:LinkButton>

在Button1_Click事件下寫伺服器端代碼
user_see為用戶端程式返回true執行Button1_Click,返回false自動不執行。
function user_see()
{
if(confirm('真的要執行伺服器端代碼?'))
{
return true;
}
else
{
return false;
}
}

這個在2.0架構下可以使用的

 

btn_del.Attributes.Add("onclick", "javascript:return del();")
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.