JavaScript中控制服务器控件事件执行
我有一个注册页面,请不要问为什么我要这样写,为什么不使用别的办法!
=======================================
注册页面 reg.aspx
========
一个用户名输入控件TEXT1
一个密 码输入控件TEXT2
一个提交按钮Button1
::::三个控件全部为服务器控件
Button1按钮代码如下:
<INPUT type= "button " id= "Button1 " value= "Button " onclick= "chdk(); " runat= "server ">
这个代码中,我加入了JS客户端脚本事件onclick= "chdk(); "
用来检测输入的用户名和密码是不是为空,
chdk()函数代码如下:
<script language= "javascript ">
function chdk()
{
if (document.Form1.Text1.value== " ")
{
alert( "请填写用户名! ");
return true;
}
if (document.Form1.Text2.value== " ")
{
alert( "请填写密码! ");
return true;
}
}
</script>
==============
reg.asp.vb文件
==============
另外,如果脚本检查输入内容都不为空的情况下,在这个文件中,我写botton1的Button1_Click的事件,把输入的内容写入数据库,代码如下:
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim zistr As String
Dim iddd As String = Request.QueryString( "id ")
Dim conn As New System.Data.SqlClient.SqlConnection( "server=JLSERVER;database=diaodu;uid=sa;pwd=123 ")
Dim shuju1 As String = Trim(Text1.Value.ToString())
Dim shuju2 As String = Trim(Text2.Value.ToString())
zistr = "update renwupiao set 用户名= ' " + shuju1 + " ',密码= ' " + shuju2 + " ' where 票号= ' " + iddd + " ' "
Dim ds As New System.Data.SqlClient.SqlCommand(zistr, conn)
conn.Open()
ds.ExecuteNonQuery()
Response.Redirect( "webform_grid.aspx ")
conn.Close()
End Sub
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
====================================================
现在问题出在我用脚本JS检查输入的用户名和密码,如果任何一个为空,我想停止代码的继续执行,提示客户重新输入,而不写入数据库!直到全部内容按要求输入无误了,检查通过后直接写入数据库!
例如:现在代码JS检查出来密码没有输入,为空,Private Sub Button1_Click里边的代码继续执行,并且写入数据库了
能不能在JAVASCRIPT里直接判断用户名和密码为空后,执行在代码内加一具代码,不叫Private Sub Button1_Click里的代码再执行了???
请高手们指教?万分感激!
[解决办法]
返回false,阻止页面post
==================================
小小姑娘
清早起床
提着裤子上茅房
茅房有人,没有办法
只好拉在裤子上..................
QQ:18163708;765835
MSN:yoursunboy@msn.com
Gtalk:yoursunboy@gmail.com
==================================
[解决办法]
上面正解
[解决办法]
2.0的话,可以用这个方法,cs文件中
button.clientScript = "if(check()) return; ";
[解决办法]
改成这样试试
<INPUT type= "button " id= "Button1 " value= "Button " onclick= "return chdk(); " runat= "server ">