62,267
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<script language="javascript" type="text/javascript">
function getValue1(){
var a=document.getElementById("tb1").value;
if(!a.match("^[0-9]*$")){
alert("请输入数字");
return false;
}
Default2.getValue(a,callback);
}
function callback(res){
var dt=res.value;
alert(dt);
return Boolean(dt);
}
</script>
<div>
<asp:TextBox ID="tb1" runat="server" Height="50px" TextMode="MultiLine"
Width="200px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="提交"
OnClientClick="return getValue1()" onclick="Button1_Click" /><br/>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default2));
}
[AjaxPro.AjaxMethod]
public bool getValue(int a)
{
if (a > 5)
{
return true;
}
else
{
return false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(tb1.Text) <6)
{
Label1.Text = "我不大于5但是被刷新了";
}
else
{
Label1.Text = "正常提交";
}
}
}
OnClientClick="return getValue1()" 为 OnClientClick="if(!getValue1()) return false;"