How does the server button trigger the submit event through JS verification?

Source: Internet
Author: User

<Script language = "JavaScript">

Function checkform (inputform)
{

If (document. getelementbyid ("txtname1"). value = "")
{
Alert ("Enter the donor name ");

Return false;
}

}

</SCRIPT>

 

 

Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
This . Button2.attributes. Add ( " Onclick " , " Return checkform () " );
}

}

 

 

Some tips in ASP. NET:

 

1, When the page is postbacks, keep the position of the scroll bar.
In ASP. NET 1.1, it is really painful to maintain the position of the scroll bar when performing the PostBack operation, especially when there is a grid (table?) on the page ?) When you want to edit a specific row. The page will be reloaded. the scroll bar is at the top of the page, not the expected position, so you have to drop down the scroll bar. In ASP. net2.0, you can simply add maintainscrollpostiononp to page ctictive.Ostback attribute (to implement the same function ).
<% @ Page Language = "C #" maintainscrollpositi autoeventwireup = "true" codefile =""Inherits =""%>
2, When a page is loaded, the control obtains the default focus.
This is another simple task, instead of writing the commit Crip script. If there is only one (or two) text input box on your page, why do users have to click the text box before entering it? The cursor cannot be automatically located in the text box. Can Users enter it immediately? You can easily use the defaultfocus attribute of the htmlform control.
<Form ID = "frm" defaultfocus = "txtusername" runat = "server">
  
</Form>

3, When you press enter, set the default trigger button.
In ASP. NET 1.1, this is a very painful thing. When you press enter, you need to write some JavascriptCodeTo ensure that the appropriate button on the page triggers a "click" event on the server side. Fortunately, when you press enter, you can use the defaultbutton attribute of htmlform to set which button to click. In another case, whenever a user (is the cursor more appropriate ?) You can set the defaultbutton attribute of the panel control when different buttons are triggered on the page.
<Form ID = "frm" defaultbutton = "btnsubmit" runat = "server">
  
</Form>

 

 

Just add something in the body.
<Body oncontextmenu = "Return false" // right-click to shield
Onselectstart = "Return false" // block the selected
Oncopy = "Return false"> // block copy

 

 

Web page shield ie right-click menu:

 

Blocking the ultimate method of right-click ie menu (just Insert the following code into

<Script language = "JavaScript" id = "clienteventhandlersjs">
<! --

Function document_oncontextmenu (){
// You can add custom code here
Return false;
}

// -->
</SCRIPT>

<Script language = "JavaScript" event = "oncontextmenu" for = "document">
<! --

return document_oncontextmenu ()
// -->

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.