anthem:TextBox 设置 ReadOnly="True" 后  在后台   获取不到文本框中的值  

解决方案 »

  1.   

    附代码。取值与readonly没什么关系
      

  2.   

    在后台直接设置,TextBox1.Attributes.Add("readonly", "readonly");
      

  3.   

      <anthem:TextBox ID="txt1" runat="server" Width="19px" ReadOnly="True">aaaaaaaa</anthem:TextBox>在.cs文件中
       txt1.Text获取到的就是 "".
      

  4.   

    弄错了  是这样,页面上有个GridView  上面我放了一个按钮,在GridView1_RowDataBound事件中添加e.Row.Cells[5].Attributes.Add("onclick", "jsFunctionName('" + e.Row.Cells[1].Text.ToString().Trim() + "','" + e.Row.Cells[2].Text.ToString().Trim() + "','" + e.Row.Cells[3].Text.ToString().Trim() + "','" + e.Row.Cells[4].Text.ToString().Trim() + "','" + e.Row.Cells[0].Text.ToString().Trim() + "')");
    在前端用    <script language="javascript" type="text/javascript">       function jsFunctionName(a,b,c,d,e)//类别 名称 规格
            {debugger;
           var str1=a;var str2=b;var str3=c;var str4=d;var str5=e;
            window.document.getElementById("txt1").value=str1;
            if(str2!="&nbsp;"){
            window.document.getElementById("txt2").value=str2;}
            if(str3!="&nbsp;"){
            window.document.getElementById("txt3").value=str3;}
            window.document.getElementById("txt4").value=str4;
            window.document.getElementById("txt5").value=str5;
            }
     </script>
    获取到,这样页面就不会刷新了,txt都是
    <anthem:TextBox ID="txt1" runat="server" Width="19px"></anthem:TextBox>
    其中txt1 必须 ReadOnly="True" 
    但是在点提交后 获取不到txt1的Text值,其他的都可以取到,
      

  5.   

    通过style设置属性
    string.isNullOrEmpty(txt1.Text)
      

  6.   

    txt1是什么?不是girdview中的控件吧?
      

  7.   

    没在girdview中,是独立的文本框
      

  8.   

    txt1.Attributes["contentEditable"] = "false"; 
      

  9.   

    放在page_load事件里
    txt1.Attributes["contentEditable"] = "false"; 
      

  10.   

    window.document.getElementById("txt1").value=str1;==>>window.document.getElementById("txt1").innerHTML=str1;
    看看会怎样?
    我不用ASP控件,对ASP控件不熟悉
      

  11.   

    你是不是在page_load事件里面写了文本框等于空啊?可能页面回传的时候给他赋了空值。
      

  12.   

    通过style设置属性  设置只读,怎么可能读不到值呢。
    string.isNullOrEmpty(txt1.Text) 是否为空 
      

  13.   

    不要设置 TextBox 的 ReadOnly="True" 因为 它在获取值的时候 会判断 ReadOnly 属性,如果为 true 是不会获取新值的使用 TextBoxID.Attributes.Add("readonly","true");
      

  14.   

    txt1.Attributes["contentEditable"] = "false"; 很正确的说