I remember that javascript is often used when asp is used. Such as the verification form and deletion confirmation. Asp. Net is a server, and our javascript has lost the space for applications. However, after some exploration, Asp. Net uses javascript very easily.
First, we will introduce the webbutes attribute of WebControl. (HtmlControl is similar and does not repeat). Attributes is a set of arbitrary features (only for rendering) that do not correspond to the properties of the control. For example, a common form Control
<Input type = "button" name = "Button" value = "Button" onClick = "ClickEvent ()">
Here, the type, name, and Button are all the attributes of the Button, and the event after The onClick Button is clicked. These can be set in Asp. Net through the Attributes attribute set.
The following is an example of Logon form verification.
<% @ Page Language = "C #" %>
<Script runat = "server">
Void Page_Load (Object sender, EventArgs e)
{
// Add the client onClick event
Button1.Attributes ["onClick"] = "return CheckForm ()";
}
</Script>
<Html>
<Head>
<Script language = "javascript">
Function CheckForm ()
{
// Verify the javascipt function of the form.
If (document. all. Username. value = "")
{
Alert ("Enter the user name ");
Return false;
}
Else if (document. all. PassWord. value = "")
{
Alert ("enter the password ");
Return false;
}
Return true;
}
</Script>
</Head>
<Body>
<Form runat = "server">
<Br/>
<Table height = "150" width = "300">