c#的textbox文本框怎样做到和input(text)输入框一样能出现失去焦点时文本框显示灰色文字的提示?input(text)文本输入框
<form action="" method="post" name="form">
<input type="text" style="color:#999" name="name" value="这是提示文字" onfocus="this.style.color='#000'; if(this.value=='这是提示文字') { this.value='' }" onblur="if(this.value=='') { this.value='这是提示文字';this.style.color='#999' }"/>
</form>下面的textbox文本框:
<td style="width: 569px" colspan="3">
     <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 328px; position: static;
     top: 138px"  Width="156px" MaxLength="20" ></asp:TextBox>
   </td>
该文本框怎样修改?

解决方案 »

  1.   


      protected void TextBox1_TextChanged(object sender, EventArgs e)
      {
            TextBox1.Style.Add("color", "red");
      }textBox的Autopostback设为true;
      

  2.   


      protected void TextBox1_TextChanged(object sender, EventArgs e)
      {
            TextBox1.Style.Add("color", "gray");
      }textBox的Autopostback设为true;
      

  3.   


        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox1.Style.Add("color", "gray");
        }
    TextBox1的autopostback属性设为true;
      

  4.   

    刚才我才做了<script type="text/javascript" language="javascript">
            String.prototype.Trim = function()//去掉空格 
            { 
            return this.replace(/(^\s*)|(\s*$)/g,""); 
            } 
            
            function onChangeValue()
            {
                var obj = document.getElementById("txtSchoolName");
                if(obj.value.Trim()=="请输入学校名称")
                {
                    obj.value="";
                    obj.style.color="Black";
                }
            }        function offChangeValue()
            {   
                var obj = document.getElementById("txtSchoolName");         
                if(obj.value.Trim()=="")
                {
                    obj.value="请输入学校名称";
                    obj.style.color="Gray";
                }
            }
        </script>
    <asp:TextBox ID="txtSchoolName" ForeColor="gray"  onclick="onChangeValue()" onblur="offChangeValue()"  runat="server">请输入学校名称</asp:TextBox><asp:Button ID="Button1"
                    runat="server" Text="查询" OnClick="Button1_Click" />
      

  5.   

    服务器控件用onfocus是没用的。我试过了,每次走的都是onblur的事件。
      

  6.   

    你的代码用onfocus是可以执行的,估计你其他地方有问题
      

  7.   

    就失去焦点的时候,给出提示信息,并改变style,焦点进来的时候把提示的信息去掉,style还原
      

  8.   

    TextBox1.Attributes.Add("onfocus", "this.style.color='#000'; if(this.value=='这是提示文字') { this.value='' }");
    TextBox1.Attributes.Add("onblur","A()");
    function A()
    {}