<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 ()
// -->