<script language='javascript'>
<!--
function checkdata() {
        if (Jtrim(document.forms['Form1'].elements['TextBox1'].value)=='') {
                window.alert ("请输入您的姓名 !")
                return false
        }
        if (Jtrim(document.forms['Form1'].elements['TextBox2'].value)=='') {
                window.alert ("密码不得为空!")
                return false
        }
      return true
}
-->
</script>
有一个按扭点后就判断<asp:button id=button1 OnClick="checkdata()"/>
后台是这么写的
void button1_OnClick(object sender,EventArgs e)
{
 Response.Write("<script>window.open(..............);</script>");
}
如果这么写就会报错,不知道如何写呢。如何在客户端做呢。

解决方案 »

  1.   

    用代码写javascript代码
    Response.Write(@"<script language=JavaScript>alert('你好!');</script>")
      

  2.   

    <asp:button id=button1  runat=server"/>然后在cs
    pageLoad()
    {
    button1.Attribuates.add("onclick","checkdata()");
    }
      

  3.   

    最好不要用验证控件,客户端验证即可。2002pine(在深圳真的很累)的是正解。
    <asp:button id=button1  runat=server"/>然后在cs
    pageLoad()
    {
    button1.Attribuates.add("onclick","checkdata()");
    }
      

  4.   

    to:2002pine(在深圳真的很累)我现在里面有一段代码
    void button1_OnClick(object sender,EventArgs e)
    {
     Response.Write("<script>window.open(..............);</script>");}
    如果在在page_load里加
    button1.Attribuates.add("onclick","checkdata()");
    会报错的。
      

  5.   

    怎么会报错,报什么错button1.Attributes .Add("onclick","checkdata()");
      

  6.   

    一个button要么在在客户端响应,要么在服务端响应。也就是说有了js的checkdata(),就不能有void button1_OnClick(object sender,EventArgs e)。
      

  7.   

    lazyfish(呆呆虫) ( ) 
    不可能吧
      

  8.   

    客户端的js代码
    <script language='javascript'>
    <!--
    function checkdata() {
            if (Jtrim(document.forms['Form1'].elements['TextBox1'].value)=='') {
                    window.alert ("请输入您的姓名 !")
                    return false
            }
            if (Jtrim(document.forms['Form1'].elements['TextBox2'].value)=='') {
                    window.alert ("密码不得为空!")
                    return false
            }
          return true
    }
    -->
    </script>
    服务器端
    void Page_Load(object sender,EventArgs e)
    {
     button1.Attributes .Add("onclick","checkdata()");
    }void button1_OnClick(object sender,EventArgs e)
    {
     SqlConnection myconn =(SqlConection)HttpContext.Current.Items(Connection);
     myconn.Open();
     strsql="select * from tablea";
     SqlCommand cmd = new SqlCommand(strsql,myconn);
    SqlDataReader dr = cmd.ExecuteReader();
    if(dr.Read())
     {
      Response.Write("<script>window.open(..............);</script>");
     }
    }
    但在状态栏上会显示页面上有错!!!!!