C#HTML控件验证表单

来源:百度知道 编辑:UC知道 时间:2024/06/24 05:11:43
看看我这哪错了,文本框为空能弹出对话框,但是为不为空都不会提交表单。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
<script type="text/javascript">
function c()
{
if(form1.proname.value=="")
{
alert("不能为空")
form1.proname.focus()
return false
}
if(form1.proinfo.value=="")
{
ale

是button的问题,这样写是不会把表单提交到后台的,button这样写:
<input id="Button1" type="submit" value="提交" onclick="return c();" />
这样修改量最小,而且又不会影响别的控件
试试吧

<script type="text/javascript">
function c()
{
if(form1.proname.value=="")
{
alert("不能为空")
form1.proname.focus()
return false
}
else
{
if(form1.proinfo.value=="")
{
alert("不能为空")
form1.proinfo.focus()
return false
}
else
{
return true;
}
}
}
</script>

提交表达需要一个action,你的表达不知道提交到什么地方,这是没有方向的。
在ASP.NET中可以配置loginurl这样配置了,看你是否可以提交
或者你就显试的在form中加上action="*.aspx/*.html"

<form id="form1" runat="server">

<input id="Button1" type="button" value="提交" runat="server" onclick="return c();" />