|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Calculate inside a form and use the same form as Insert record formI have 3 fields in an aspx page. The 3. field should be the sum of field A
and field B I use OnTextChanged to calculate the sum in field3. At the same time I want to insert the content of theese 3 fields into a row in a table. The problem is that I need 'postback is true' on the textfields to get an immediate calculation and then the insert action is triggered. reidarT Hey reidar,
You don't have to do the postback thing. You can use some javascript to achieve the same result. Say you have three textboxes: txtFirst,txtSecond,txtSum To get txtSum to be calculated do the following: In the aspx html code add the following function <script language=javascript> function check(){ if(parseInt(document.getElementById('txtFirst').value,10)!="NaN" && parseInt(document.getElementById('txtSecond').value,10)!="NaN"){ document.getElementById('txtSum').value = parseInt(document.getElementById('txtFirst').value,10) + parseInt(document.getElementById('txtSecond').value,10) } } </script> This is basically some javascript that calculate the sum of the first two textboxes and stores the result in the third. The 10 argument to parseInt is not redundant ... if you have a number starting with 0 in either of the text boxes the javascript engine will think it is an octal number Then in your code behind do this: If Not IsPostBack Then txtFirst.Attributes.Add("onChange", "check()") txtSecond.Attributes.Add("onChange", "check()") End If On Thu, 30 Nov 2006 19:49:41 +0100, "reidarT" <rei***@eivon.no> wrote: Bits.Bytes.>I have 3 fields in an aspx page. The 3. field should be the sum of field A >and field B >I use OnTextChanged to calculate the sum in field3. >At the same time I want to insert the content of theese 3 fields into a row >in a table. >The problem is that I need 'postback is true' on the textfields to get an >immediate calculation and then the insert action is triggered. >reidarT > -- http://bytes.thinkersroom.com Reidar,
Doing this with "on text change" is in my idea completely foolish over ASPX. Beside the advise from Rad, you can have a look what Ajax can do for you. (Just to experiment, because the advise from Rad is in my idea better). http://ajax.asp.net/ Cor Show quoteHide quote "reidarT" <rei***@eivon.no> schreef in bericht news:Osy8OBLFHHA.3540@TK2MSFTNGP02.phx.gbl... >I have 3 fields in an aspx page. The 3. field should be the sum of field A >and field B > I use OnTextChanged to calculate the sum in field3. > At the same time I want to insert the content of theese 3 fields into a > row in a table. > The problem is that I need 'postback is true' on the textfields to get an > immediate calculation and then the insert action is triggered. > reidarT >
Re: Is VB.NET Stable?? To Aaron Kemp - Ahole Extrordinare
String to Byte & Vice Versa End Processing in Multithreaded App Best way to communicate from Desktop to SQL DB Re: Is VB.NET Stable?? Create Property on the fly Cross-thread operation not valid. catching close button Re: Is VB.NET Stable?? Transparent text box. |
|||||||||||||||||||||||