<%@ Page language="c#" Codebehind="ValidNow.aspx.cs" AutoEventWireup="false" Inherits="Samples.ValidNow" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
		<title>实现即时验证功能示例</title>
</HEAD>
<body MS_POSITIONING="FlowLayout" onload="window_onload()">
<script language="javascript">
    // 通过这个变量判断股票名称是否改变
    var tickerChanged = false;
    //“股票名称”文本控件内容改变事件
    function TickerChange()
            {
			if(event.propertyName=="value")
				{
				tickerChanged = true;
				document.all.form.submitButton.disabled=true;			
				}
            }
    //“数量”文本控件获得焦点事件
    function SharesFocus()
            {
            //如果股票名称改变，则提交页面进行验证，并返回股票价格 
            if(tickerChanged)
                {           
                var theform = document.forms[0];
                // 这是一个自定义标识，表示是否是用户单击提交按钮
				theform.buttonClick.value = 'false';		            
				theform.submit();
                }
            }
	function window_onload()
		{
		if (document.all)
			{
			if(document.all.shares)
				{
				//通过股票价格标签，判断股票名称是否验证有效
				if(document.all.price.innerText.substring(0,1)=="@")
					{
					document.all.shares.focus();
					document.all.form.submitButton.disabled=false;			
					}
				else
					{
					document.all.symbol.select();
					document.all.symbol.focus();
					document.all.form.submitButton.disabled=true;
					}
				}
			}
		}
</script>
<form id="form" method="post" action="ValidNow.aspx" runat="server">
<asp:ValidationSummary ID="validationSummary" runat="server" HeaderText="" />
<input type="hidden" name="buttonClick" value="true">
	<p class="section">买股票</p>
	<table cellpadding="0" cellspacing="0">
		<tr><td width="100">股票名称：</td>
			<td><input type="text" id="symbol" maxlength="6" onPropertyChange='TickerChange()' runat="SERVER" NAME="symbol"></td>
		</tr>
		<tr><td>数量：</td>
			<td><input type="text" id="shares" maxlength="8" runat="SERVER" onFocus='SharesFocus()' NAME="shares">
				<b><asp:Label id="price" runat="SERVER" /></b></td>
		</tr>
		<tr><td>&nbsp;</td>
			<td><br><input type="submit" id="submitButton" value="购买" runat="SERVER" NAME="submitButton"></td>
		</tr>
	</table>
	<asp:RequiredFieldValidator id="RequiredSharesValidator" ControlToValidate="shares" ErrorMessage="数量不能为空！" Display="None" InitialValue="" Width="100%" runat="server"></asp:RequiredFieldValidator>
	<asp:RangeValidator id="RangeSharesValidator" Type="Integer" ErrorMessage="数据量必须为整数！" ControlToValidate="shares" MinimumValue="1" MaximumValue="99999999" Display="None" runat="server"></asp:RangeValidator>
	<asp:RequiredFieldValidator id="RequiredTickerValidator" ControlToValidate="symbol" ErrorMessage="股票名称不能为空！" Display="None" InitialValue="" Width="100%" runat="server"></asp:RequiredFieldValidator>
	<asp:CustomValidator id="CustomTickerValidator" runat="server" ControlToValidate="symbol" ErrorMessage="股票名称无效！" OnServerValidate="ServerValidateTicker" Display="None"></asp:CustomValidator>
    </form>
</body>
</HTML>
