Tutorials to .com

Tutorials to .com » Dotnet » Control-and-components » For the server control to add client-side javascript event

For the server control to add client-side javascript event

Print View , by: iSee ,Total views: 14 ,Word Count: 509 ,Date: Thu, 21 May 2009 Time: 11:04 AM

asp remember a time with regular use javascript. For example, form validation, delete confirmation. Asp.Net is a server-side, we lost the javascript space applications. However, after a trial, in fact, the use of javascript is very simple Asp.Net.


First introduce the Attributes property of the WebControl. (HtmlControl almost will not repeat), Attributes and controls access to the property does not correspond to any characteristic (for show only) collection. For example, a common form of control
<input type="button" name="Button" value="Button" onClick="ClickEvent()">
The type, name, Button are attributes of the button, onClick button click events. Asp.Net all these can be set to set the Attributes property.





Take the following example to verify the login form.
<% @ Page Language = "C #"%>
<script runat="server">
void Page_Load (Object sender, EventArgs e)
(
/ / Add client-side onClick event
Button1.Attributes [ "onClick"] = "return CheckForm ()";
)
</ script>

<html>
<head>
<script language="javascript">
function CheckForm ()
(
/ / Validate form function javascipt
if (document.all.Username.value =="")
(
alert ( "Please fill in user name");
return false;
)
else if (document.all.PassWord.value =="")
(
alert ( "Please fill in your password");
return false;
)
return true;
)
</ script>
</ head>
<body>
<form runat="server">
<br />
<table height="150" width="300">
<tbody>
<tr>
<td>
Username </ td>
<td>
<asp:TextBox id="Username" runat="server"> </ asp: TextBox>
</ td>
</ tr>
<tr>
<td>
Password </ td>
<td>
<asp:TextBox id="PassWord" runat="server" TextMode="Password"> </ asp: TextBox>
</ td>
</ tr>
<tr>
<td>
</ td>
<td>
<asp:Button id="Button1" runat="server" Text=""> </ asp: Button>
</ td>
</ tr>
</ tbody>
</ table>
</ form>
</ body>
</ html>

Is not familiar with the way back:)


.Net Control and components Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.