TextBox值未分配给asp.net中的变量 [英] TextBox value not assigning to variable in asp.net

查看:63
本文介绍了TextBox值未分配给asp.net中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function outputtax()
 {
 var tamount = parseFloat(document.getElementById('<%=txtpsubtotal.ClientID%>').value);
 var cash = parseFloat(document.getElementById('<%=txtpdiscount.ClientID%>').value);

 if (isNaN(tamount) != true && isNaN(cash) != true )
  {
    document.getElementById('<%=txtPtotalamout.ClientID%>').value =
       Math.round(parseFloat(document.getElementById('<%=txtpsubtotal.ClientID%>').value)
  - parseFloat(document.getElementById('<%=txtpdiscount.ClientID%>').value))
      return false;
    }

  }

<asp:TextBox ID="txtPtotalamout" runat="server" ReadOnly="true">
                                          </asp:TextBox>





**。CS **





**.CS**

objsupplyPL.totalamount = Convert.ToDouble(txtPtotalamout.Text.ToString());





价值显示在文本框上但当我点击保存按钮`txtptotalamount`正在获得

`null` value。如果我放置`readonly =false`它工作正常。



Value is displaying on the textbox but when i click save button `txtptotalamount` is getting
`null` value.If I placed `readonly="false"` it's working fine.

推荐答案

尝试添加

Try adding
protected void Page_Load(object sender, EventArgs e)

{
 if(!IsPostBack)
 {
   txtPtotalamout.Attributes.Add("readonly","readonly");
 }
}


当您通过JavaScript设置控件的值时,无论服务器端是否为只读属性,它都会被设置。

但是当你通过按钮点击进行回发时,该值将成为回发变量的一部分。当服务器尝试在文本框中呈现值时,它会发现它只读它所以它将无法设置值。



此外值将是永远不是null而是空字符串。



尝试在PagePreRender而不是aspx中设置此属性以延迟文本框上的锁定。对于最终用户,它仍将被呈现为只读,只是服务器将有机会将值放在回发上
When you set the value of control through JavaScript it will get set regardless of the server side read-only property.
However when you do a postback through button's click, that value will be part of the postback variable. When the server will try to render the value inside the textbox, it will find it as readonly so it will not be able to set the value.

Also the value will never be "null" but an empty string.

Try setting this property upon PagePreRender rather than in aspx to delay the lockup on textbox. It will still be rendered as readonly for the end user, just that server will get a chance to put the value upon postback


请输入更多细节,你确定你没有做到其他文本框readonly = true?
please put more detail, are you sure you didn't make the other textboxes readonly=true ?


这篇关于TextBox值未分配给asp.net中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆