我用javaScript改变TextBox值,当执行鼠标事件时TextBox还为原来的值,而且页面刷新后的显示值也变为原来的了, 
这是怎么回事,该怎么解决?

解决方案 »

  1.   

    textbox绑定值写在if(!ispostback)里面
      

  2.   

    document.getElementById("textBoxID").value = "要设的值"; 
      

  3.   

    你的后台代码最好都写在if(!ispostback)里
      

  4.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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>
        <script type="text/javascript">
            function  aaa()
            {
                document.getElementById("TextBox1").value="1231231";
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox runat="server" Text="" ID="TextBox1"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
            <input type="button" value="12312" onclick="aaa()" />
        </div>
        </form>
    </body>
    </html>
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write(TextBox1.Text);
        }
    }
      

  5.   

    后台用Request.Form[TextBox.ClientID]
      

  6.   

    要用客户端控制id.....document.getElementById("<%=TextBox1.ClientID%>").value = "要设的值"; 
      

  7.   

    !ispostback
    估计是这个问题吧。
      

  8.   

    document.getElementById("<%=TextBox1.ClientID%>").value = "要设的值";