我用的是VS2005,请问按BUTTON执行Alert后为什么TextBox高度会变小。请各们大虾指点迷津,我知道如果把
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">去除后就可以解决。但我不知道为什么会是这样,这段代码的含义是什么?一定要这样才能解决问题吗?
如下是所有代码,因老弟是.NET纯属自学,所以没有多少分。1.cc.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cc.aspx.cs" Inherits="cc" %>
<!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>
    <style type="text/css">
    #TextBox1,#a{height:25px;}
    input[type="text"]{height:30px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">        <input type="text" name="a" id="a" value="" />
        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    </form>
</body>
</html>
2.cc.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class cc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('为什么TextBox高度会变小?');</script>");
    }
}

解决方案 »

  1.   

    用Response.Write输出弹出框会破坏脚本,用
    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", " <script>alert('为什么TextBox高度会变小?'); </script>")
      

  2.   

    楼主这样会使页面丢掉加载的CSS
    Response.Write(" <script>alert('为什么TextBox高度会变小?'); </script>"); 
    用以下两种方法
    1:
      Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", " <script>alert('为什么TextBox高度会变小?'); </script>")2:加一个lable,text属性设为空,
       protected void Button1_Click(object sender, EventArgs e) 
        { 
            lable1.text=" <script>alert('为什么TextBox高度会变小?'); </script>"; 
        } 
      

  3.   

    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", " <script>alert('aaa'); </script>")
      

  4.   

    用这样写可能有题!
    Response.Write

    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", " <script>alert('test'); </script>")
    这样写应没问题的!
      

  5.   

    Response.Write(" <script>alert('为什么TextBox高度会变小?'); javascript:history.go(-1); </script>");  也可以好象
      

  6.   

    十分感谢众师付。
        另外想问一下7楼的“javascript:history.go(-1); ”在此时表示什么意思?
         
      

  7.   

    response.write写入alert脚本就是会这样,有时css样式会全部没有掉