这是后台代码 
protected void txtMan_Count_TextChanged(object sender, EventArgs e)
    {
        receive_line receiveline = receive_lineService.FindReceiveLineById(Int32.Parse(this.ObjectId));
        int ManCount = 0;
        int ChildCount = 0;
        try
        {
            ManCount = Int32.Parse(txtMan_Count.Text);
            ChildCount = Int32.Parse(txtChild_Count.Text);
        }
        catch
        {
            warnDiv.InnerText = "人数只能为数字,请检查您输入的信息是否有误!";
            warnDiv.Attributes.Add("style", "display:block");
        }
        total_price.InnerText = (ManCount * receiveline.man_sale_price + ChildCount * receiveline.child_sale_price).ToString();
前台文本框代码 
 成人
                        <asp:TextBox ID="txtMan_Count" Width="20px" Height="18px" runat="server" 
                            Text="1" ontextchanged="txtMan_Count_TextChanged"></asp:TextBox>人
                        &nbsp;&nbsp;&nbsp;儿童
                       <asp:TextBox ID="txtChild_Count" Width="20px" Height="18px" runat="server" 
                            Text="0" ontextchanged="txtMan_Count_TextChanged"></asp:TextBox>人
                        &nbsp;&nbsp;&nbsp;(金额总计:<b id="total_price"  runat="server"></b>起)<div id="warnDiv" runat="server" style="display:none; color:Red;"></div>
    }

解决方案 »

  1.   

    当textbox里面内容变化是会触发OnTextChanged事件。但是只有在页回发给服务器时才会触发texchanged事件。textbox控件本身并不会生成回发,只有当页面的另一个控件强制回发时才能触发textchanged事件。当你把textbox控件的autopostback属性设置为true,当控件文本发生变化时强制发生回发。但是它只有在失去焦点时才会激发ontextchanged事件。
      

  2.   

    的确是那个问题,那么还有别的方法在后台判断文本框改变么,我不想要页面的页面刷新效果,JS写好了,但是怕用户禁用JS,所以还想在后台判断一次
      

  3.   

    ++1<asp:TextBox ID="txtMan_Count" Width="20px" Height="18px" runat="server"  
      Text="1" ontextchanged="txtMan_Count_TextChanged" AutoPostBack="true"></asp:TextBox>
      

  4.   

    ScriptManager  那就用这个ajax 控件好了...其实用js验证就可以了的....
      

  5.   

    老板禁止用ScriptManager控件,用户禁用JS脚本的话,AJAX还有效么这个我还真没试过