Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI All,

I have a simple client side calculation in my application.
Situation is like,

I have 3 textboxes. Say txt1,txt2,txt3.
txt3 = txt1 + txt2

my javascript works fine which is something like
JavaScript
document.getElementbyID('<%=txt3.ClientID%>').value = Number(document.getElementbyID('<%=txt1.ClientID%>').value) + Number(document.getElementbyID('<%=txt2.ClientID%>').value); 

I get result on client side. But when i write txt3.text in server side code i get nothing.

txt3 is readonly i tried to make it readonly false and it worked fine but how can I make it with readonly true?

Please some one can help me....

Thanks in advance.
Posted
Updated 6-Mar-12 1:06am
v2
Comments
Anuja Pawar Indore 6-Mar-12 7:06am    
Added code block

Here's a simple sample to see that it works:

DebugQuery.html simply shows the query string:
XML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Simple Querystring Debugging</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Just a simple check for the query string!</br>
</body>
<script type="text/javascript">
document.write("<b>Querystring:</b> " + document.location.search);
</script>
</html>


ReadOnly.html contains the small test HTML markup:
XML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onload="init();">
<form id="testForm" method="GET" action="./DebugQuery.html">
    <input ID="test" NAME="realname" VALUE="Hi There" READONLY>
    <input ID="submit" type="submit" name="submit" value="Send!">
</form>
<input ID="doit" type="button" NAME="doIt" VALUE="Set to 10!" onclick="doIt();">
</body>
<script type="text/javascript">
function init()
{
    var test = document.getElementById("test");
    test.value = "0";
}

function doIt()
{
    var element = document.getElementById("test");
    element.value = 10;
}
</script>
</html>


Regards,

Manfred
 
Share this answer
 
Comments
Anuja Pawar Indore 6-Mar-12 8:26am    
Perfect my 5
Manfred Rudolf Bihy 6-Mar-12 9:00am    
Thank you :)
Yo need to post back the fields to get them back on the server. This also means that txt3 needs to be part of the form that is posted back. Can't see that because that code isn't shown here but you could check it out.

Good luck!
 
Share this answer
 
Comments
hiren soni 6-Mar-12 7:32am    
Thanks for your reply but can you please provide an example? And what do you mean by txt3 should be the part of the form?
E.F. Nijboer 7-Mar-12 3:28am    
I guess Manfred gave you the example you were looking for.
ps. Would be nice if you would mark it to solved based on his answer.
instead of single quotes try doubles quotes
document.getElementbyID("<%=txt3.ClientID%>").value =
 
Share this answer
 
Instead of setting property to readonly from property window. I set the attribute like this:
C#
txt3.Attributes.Add("readonly","readonly");


And it works fine.

Thanks a lot to all for your responses.
 
Share this answer
 
v2
u can add that text field using hidden field.first the take the data returned by script in hidden filed and append that to your text field..
 
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