我写了一个登陆页面,用JS判断两个文本框是否为空,点“登陆”图片按钮为什么还一闪一闪的,感觉应该是提交到服务器端了,请问这是什么原因?
我执行的是客户端脚本,应该不会这样才对呀?
Aspx 脚本如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="登陆.aspx.cs" Inherits="登陆" %>
<!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  src="js/myJScript.js" ></script>        <form id="form1" runat="server">
            <div>
                  <br />
                 </div>
            <table align="center" cellpadding="0" cellspacing="0" style="border-right: #ff3366 thin solid;
                border-top: #ff3366 thin solid; border-left: #ff3366 thin solid; width: 581px;
                border-bottom: #ff3366 thin solid">
                <tr>
                    <td style="width: 34px; height: 22px; text-align: right">
                        <strong><em>Name:</em></strong></td>
                    <td style="width: 217px; height: 22px">
                        <asp:TextBox ID="txt_Name" runat="server" Height="26px" Style="position: relative"
                            Width="228px"></asp:TextBox></td>
                    <td rowspan="3" style="width: 41px">
                        <asp:ImageButton ID="ImageButton1" runat="server" Height="137px" ImageUrl="~/image/TV.jpg"
                            Style="position: static" Width="259px" /></td>
                </tr>
                <tr>
                    <td style="width: 34px; height: 22px; text-align: right">
                        <strong><em>Pwd:</em></strong></td>
                    <td style="width: 217px; height: 22px">
                        <asp:TextBox ID="txt_Pwd" runat="server" Height="26px" Style="position: relative;
                            top: 1px" TextMode="Password" Width="228px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 34px; border-right-style: dashed; height: 67px; border-right-color: #6699ff">
                    </td>
                    <td style="width: 217px; height: 67px">
                         <asp:ImageButton ID="btn_ok"  runat="server" Height="34px" ImageUrl="~/image/login.GIF"
                          Style="left: 0px; position: relative; top: 0px" Width="102px" OnClientClick="check()"  />
                        
                        <asp:ImageButton ID="btn_exit" runat="server" Height="34px" ImageUrl="~/image/cancel.gif"
                            Style="left: 0px; position: relative; top: 0px" Width="102px" OnClick="btn_exit_Click" />
                    </td>
                </tr>
            </table>
        </form>
    
</body>
</html>
**********************\\   myJScript.js   \\**************************
function check()
    {
       var txt1 = document.getElementById("txt_Name");
       var txt2 = document.getElementById("txt_Pwd");    
         //alert("请输入用户名!");
         
           
           
          if (txt1 && txt1.value=='')
          {          
            alert("请输入用户名!",64,"系统提示");
            txt1.focus();
            return false;
          }
    
        if (txt2 && txt2.value=='')
        { 
           alert("密码不能为空!");
           txt2.focus();
           return false;
        }
           return true;
    } 

解决方案 »

  1.   

    那是因为你用的还是服务器控件啊,你可以改为使用客户端控件<img/>
      

  2.   

    onclientclick用这个事件是在客户端判断的,onclick是在服务器端的
      

  3.   


    我是用的这个事件呀:onclientclick
    另非要用“客户端控件 ”?
      

  4.   

     <asp:ImageButton ID="btn_ok"  runat="server" Height="34px" ImageUrl="~/image/login.GIF" 
                              Style="left: 0px; position: relative; top: 0px" Width="102px" OnClientClick="check()"  /> 
      你使用HTML标签试试
      

  5.   

    应该用服务器端控件,如果是客户端控件,验证通过了怎么提交到服务器?
    你改下:OnClientClick = "return check()"