日期:2014-05-20  浏览次数:20505 次

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
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '