<script language="javascript" type="text/javascript">
function Calcaulate()
    {
       
       if(document.getElementById("drpPhoneList").value=="Home Phone Lite")
       {
         var txtRegular= document.getElementById("txtRegularRs").value;
         document.getElementById("txtTotalRegularRs").value=parseFloat(txtRegular);
         document.getElementById("TotalRsTaxes").value=parseFloat(txtRegular)+parseFloat(3.63);
        
       } 
</script>

    <input type="button" value="CALCULATE" onclick="Calcaulate()" class="button" />
<asp:Button ID="btnAdd" runat="server" Text="ADD" OnClientClick="return Validations()"
                    OnClick="btnAdd_Click" class="button"/>

as i have two buttons one is html and other is aps.net button what i want to do is that first i want to make calculation on client side as shown in above code of calculate function of javascript after calculation i want to insert the result in to sqlserver db by clicking on the asp.net button but when post back occurs it can not maintain the result it just clears the textbox what should i do any trick for that

Recommended Answers

All 8 Replies

On the page_load event check you

Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
if TotalRsTaxes.text.length > 0 then
session("TotalRsTaxes") = TotalRsTaxes.text
end if
end sub

On Button click Retrive the same Values

TotalRsTaxes.text = session("TotalRsTaxes")

Mark as solved if it helps you!!!

thx for ur such reply yousf! i tried the code that u have written but it's not working still the same problem text box gets cleard when page is post back by clicking on serverside button control.i haven't worked with javascript b4 iam in my infancy with that plzzz help

Yes the textbox will always be clear. there is only one Solution to this , is to use Ajax.if the flickering of the page causes this, what you need to do, is to add a scriptmanager to your page and add an updatepanel and add the textbox inside the Update panel. This solution will only work for a asp.net Textbox , but if its a html textbox then after the calculation you need to reassign the session value to the textbox as reach_yousuf demostrated.use the alerts to check the contents of the session.

Yes the textbox will always be clear. there is only one Solution to this , is to use Ajax.if the flickering of the page causes this, what you need to do, is to add a scriptmanager to your page and add an updatepanel and add the textbox inside the Update panel. This solution will only work for a asp.net Textbox , but if its a html textbox then after the calculation you need to reassign the session value to the textbox as reach_yousuf demostrated.use the alerts to check the contents of the session.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                 <ContentTemplate>
                    <asp:TextBox ID="TotalRsTaxes" runat="server" Enabled="false" >0</asp:TextBox>
                 </ContentTemplate>
                </asp:UpdatePanel>

THX FOR UR POST AS U SAID I GUESS I DID THAT BUT STILL I AM FACING THE SAME PROBLEM TEXT BOX GETS CLEARD. OK NOW I AM GOING TO GIVE U AGAIN THE FULL DETAIL THAT HOW MY APPLICATION WORKS

I HAVE THREE TEXT BOXES TXT1,TXT2,TXT3 OF ASP.NET NOW THE VALUES IN TXT1 AND TXT2 COMES FROM DATA BASE NOW I HAVE BUTTON OF HTML WHERE I USE JAVASCRIPT CODE AS IN 1ST POST I HAVE GIVEN THE CODE A FUCNTION CALCULATION WILL BE EXECUTED AND AFTER THIS THE VALUE TXT1+TXT2 WILL BE ASSIGN TO TXT3 AND AFTER THE VALUE PLACED IN TXT3 NOW I HAVE ASP.NET BUTTON WHEN DOESN'T HAVE ANY CODE I JUST TRIED THIS BUTTON FOR THE SENSE OF POSTBACK I JUST WANT TO CHECK THAT BY POSTING BACK WEITHER THE VALUE REMAIN IN TXT3 OR NOT BUT WHEN I CLICK ON ASP.NET BUTTON AFTER POSTBACK TXT3 BECOME CLEAR NOW I HOPE THAT U HAVE GOOD DETAIL ABOUT MY WORK THAT WHAT I WANT TO DO THXXXXXXXX PLZZZZZZ HELP THIS ONE

Hi Guys

You can try Page_Prerender Event instead of Page load coz page_prerender fires and earlier than Page_load. Pls. try and let me know and dont forget to mark as solved if it helps you.

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

if TotalRsTaxes.text.length > 0 then
session("TotalRsTaxes") = TotalRsTaxes.text
end if

    End Sub

On button click the retrive the same

TotalRsTaxes.text = session("TotalRsTaxes")

Hi Guys

You can try Page_Prerender Event instead of Page load coz page_prerender fires and earlier than Page_load. Pls. try and let me know and dont forget to mark as solved if it helps you.

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

if TotalRsTaxes.text.length > 0 then
session("TotalRsTaxes") = TotalRsTaxes.text
end if

    End Sub

On button click the retrive the same

TotalRsTaxes.text = session("TotalRsTaxes")

still it doesnt work do u have hotmail ,yahoo id comone messenger we might have better discussion on that my ids are jamshed_ahmed2@yahoo.com, jamshed_ahmed2@hotmail.com

Hi Guys

You can try Page_Prerender Event instead of Page load coz page_prerender fires and earlier than Page_load. Pls. try and let me know and dont forget to mark as solved if it helps you.

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

if TotalRsTaxes.text.length > 0 then
session("TotalRsTaxes") = TotalRsTaxes.text
end if

    End Sub

On button click the retrive the same

TotalRsTaxes.text = session("TotalRsTaxes")

ok mr yousf thx for your help i got a solution it was very simple i set text fields as enabled=false that's why values were cleard i set textboxes enable to true and in page load i have just code single line txt.attributes.add("readonly","readonly")

Yes the textbox will always be clear. there is only one Solution to this , is to use Ajax.if the flickering of the page causes this, what you need to do, is to add a scriptmanager to your page and add an updatepanel and add the textbox inside the Update panel. This solution will only work for a asp.net Textbox , but if its a html textbox then after the calculation you need to reassign the session value to the textbox as reach_yousuf demostrated.use the alerts to check the contents of the session.

ok thx for your help i got a solution it was very simple i set text fields as enabled=false that's why values were cleard i set textboxes enable to true and in page load i have just code single line txt.attributes.add("readonly","readonly")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.