How to add JS events to buttons in Asp.net

Source: Internet
Author: User

There is a button in the form to add and use. In the protected void add_button_click (Object sender, eventargs E) of this button, data is added to the database. However, at the same time, I want to click this button to perform JS Form validation on the form. I don't know how to implement it. I tried to add an onclick time for the button in page_load to trigger a JS script, in this case, you cannot click the button to add it. What should I do?

 

<Asp: linkbutton id = "linkbutton1" runat = "server" onclick = "button1_click" onclientclick = "javascript: Return user_see ()"> View </ASP: linkbutton>

Write Data to the server in the button#click eventCode
User_see is the clientProgramReturns true to execute button#click, and returns false to automatically stop executing.
Function user_see ()
{
If (confirm ('Do you really want to execute the server code? '))
{
Return true;
}
Else
{
Return false;
}
}

This can be used in the 2.0 Framework

 

Btn_del.attributes.add ("onclick", "javascript: Return del ();")
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.