Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
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**

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


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.
Posted
Updated 13-Sep-13 6:16am
v3
Comments
Dholakiya Ankit 13-Sep-13 23:50pm    
why you are assigning readonly to textbox?
Bhagavan Raju M 14-Sep-13 0:48am    
User should not edit the text box
Dholakiya Ankit 14-Sep-13 0:55am    
so you are adding value through javascript and then taking that value from c# so assingning readonly =false does not get a solution?
Bhagavan Raju M 15-Sep-13 9:59am    
@dholakiya what you said is right.

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

{
 if(!IsPostBack)
 {
   txtPtotalamout.Attributes.Add("readonly","readonly");
 }
}
 
Share this answer
 
Comments
Bhagavan Raju M 14-Sep-13 0:50am    
@jocodes its not working . I am getting empty string. Thanks for ur effort
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
 
Share this answer
 
please put more detail, are you sure you didn't make the other textboxes readonly=true ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900