I HAVE 3 TEXTBOXES (txt1,txt2,txt3) WITH TWO BUTTONS ONE IS HTML BUTTON NAMED AS btnCalculate AND OTHER IS SERVER SIDE BUTTON NAMED AS btnAdd WHAT PROBLEM BOOTHER ME IS THAT VALUES COMES FROM DATA BASE FOR txt1 AND txt2 WHEN I PRESS btnCalculate JAVASCRIPT CODES ARE EXECUTED TO MAKE ADDITION OF txt1,txt2 AND ASSIGN IT TO txt3 AND FINALLY WHEN I PRESS THE btnAdd the txt3 FIELD BECOME 0 DUE TO THE POST BACK AND I HAVE TO INSERT THE txt3 VALUE TO DATABASE BUT IT INSERTS ONLY 0 ALWAYS SO PLZZZ HELP I AM VERY NEW TO ASP.NET AND JAVASCRIPT

I HAVE 3 TEXTBOXES (txt1,txt2,txt3) WITH TWO BUTTONS ONE IS HTML BUTTON NAMED AS btnCalculate AND OTHER IS SERVER SIDE BUTTON NAMED AS btnAdd WHAT PROBLEM BOOTHER ME IS THAT VALUES COMES FROM DATA BASE FOR txt1 AND txt2 WHEN I PRESS btnCalculate JAVASCRIPT CODES ARE EXECUTED TO MAKE ADDITION OF txt1,txt2 AND ASSIGN IT TO txt3 AND FINALLY WHEN I PRESS THE btnAdd the txt3 FIELD BECOME 0 DUE TO THE POST BACK AND I HAVE TO INSERT THE txt3 VALUE TO DATABASE BUT IT INSERTS ONLY 0 ALWAYS SO PLZZZ HELP I AM VERY NEW TO ASP.NET AND JAVASCRIPT

check the propertie auto post back of txt1,txt2,txt3 if its true make it false then also pblm is there pls past the coding .

check the propertie auto post back of txt1,txt2,txt3 if its true make it false then also pblm is there pls past the coding .

protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            
            Operations op = new Operations();
                if (chkHomePhone.Checked == true)
                {           
op.ADD_HOME_PHONE_DETAIL(drpPhoneList.Text, txtCallingFeatures.Text, txtAddOns.Text, drpLDPlan.Text, txtConCharges.Text, txtAcctNo.Text, Convert.ToInt32(TotalRsTaxes.Text), txtDate.Text, txtTime.Text, txtVerifierName.Text, txtAgentName.Text, lblRecordAdded, lblError);
                
                }
           
        }
        catch (Exception exe)
        {
            lblError.Visible = true;
            lblError.Text = exe.Message;
        }

 public void ADD_HOME_PHONE_DETAIL(string ArgPhoneLine, string ArgCallingFeatures, string ArgAddOn, string ArgLDPlan, string ArgConnectionCharges, string ArgAcctNumber, int ArgTotalAmount, string ArgSaleDate, string ArgSaleTime, string ArgVerifierName, string ArgAgentId,Label ArgRecrodAdded,Label ArgError)
    {
        try
        {
            MyConnection con = new MyConnection();
            cmd = new SqlCommand();
            cmd.Parameters.Clear();
            cmd.Connection = con.con;
            cmd.Connection.Open();


            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "ADD_HOME_PHONE_INFO";


            SqlParameter phoneline = new SqlParameter("@phoneline", SqlDbType.VarChar);
            SqlParameter callingfeature = new SqlParameter("@callingfeature", SqlDbType.VarChar);
            SqlParameter addon = new SqlParameter("@addon", SqlDbType.VarChar);
            SqlParameter longdistanceplan = new SqlParameter("@longdistanceplan", SqlDbType.VarChar);
            SqlParameter connectioncharges = new SqlParameter("@connectioncharges", SqlDbType.VarChar);
            SqlParameter acctnumber = new SqlParameter("@acctnumber", SqlDbType.VarChar);
            SqlParameter totalamount = new SqlParameter("@totalamount", SqlDbType.Int);
            SqlParameter saledate = new SqlParameter("@saledate", SqlDbType.SmallDateTime);
            SqlParameter saletime = new SqlParameter("@saletime", SqlDbType.SmallDateTime);
            SqlParameter verifier = new SqlParameter("@verifiername", SqlDbType.VarChar);
            SqlParameter agentid = new SqlParameter("@agentid", SqlDbType.VarChar);

            cmd.Parameters.AddWithValue("@phoneline", ArgPhoneLine);
            cmd.Parameters.AddWithValue("@callingfeature", ArgCallingFeatures);
            cmd.Parameters.AddWithValue("@addon", ArgAddOn);
            cmd.Parameters.AddWithValue("@longdistanceplan", ArgLDPlan);
            cmd.Parameters.AddWithValue("@connectioncharges", ArgConnectionCharges);
            cmd.Parameters.AddWithValue("@totalamount", ArgTotalAmount);
            cmd.Parameters.AddWithValue("@acctnumber", ArgAcctNumber);
            cmd.Parameters.AddWithValue("@saledate", ArgSaleDate);
            cmd.Parameters.AddWithValue("@saletime", ArgSaleTime);
            cmd.Parameters.AddWithValue("@verifiername", ArgVerifierName);
            cmd.Parameters.AddWithValue("@agentid", ArgAgentId);

            if (cmd.ExecuteNonQuery() > 0)
            {
                ArgRecrodAdded.Text = "RECORD IS SUCCESSFULLY ADDEDD...";
            }
            
        }
        catch (Exception exe)
        {
            ArgError.Visible = true;
            ArgError.Text = exe.Message;
        }
   
JAVA SCRIPT CODEING IS HERE 


function Validations()
	{
	if(document.getElementById("txtVerifierName").value=="")
	{
	alert("PLEASE ENTER VERIFIER NAME..");
	return false;
	}
		
	if(document.getElementById("chkHomePhone").checked==false)
	{
	alert("PLEASE SELECT HOMEPHONE CETEGORY");
	return false;
	}
	}

<asp:Button ID="btnAdd" runat="server" Text="ADD" OnClientClick="return Validations()" onclick="btnAdd_Click"  />

HERE IS THE CALCULATION CODING IN JAVASCRIPT

function Calcaulate()
    {
       if(document.getElementById("txtRegularRs").value=="")
       {
       alert("REGULAR TEXT IS EMPTY PLEASE ENTER VALUES");
       return false;
       }
       
       if(document.getElementById("txtLdPlanRs").value=="")
       {
       alert("LD PLAN TEXT IS EMPTY PLEASE ENTER VALUES");
       return false;
       }
       
      var txtRegular= document.getElementById("txtRegularRs").value;
      var txtLDPlan=document.getElementById("txtLdPlanRs").value;
       
      document.getElementById("txtTotalRegularRs").value=parseFloat(txtRegular)+parseFloat(txtLDPlan);
       
      document.getElementById("TotalRsTaxes").value=parseFloat(txtRegular)+parseFloat(txtLDPlan)+parseFloat(3.63);


<input type="button" value="CALCULATE" onclick="Calcaulate()"/>

THIS IS TOTAL CODING OF MY CURRENT PROJECT PLZZ HLP

protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            
            Operations op = new Operations();
                if (chkHomePhone.Checked == true)
                {           
op.ADD_HOME_PHONE_DETAIL(drpPhoneList.Text, txtCallingFeatures.Text, txtAddOns.Text, drpLDPlan.Text, txtConCharges.Text, txtAcctNo.Text, Convert.ToInt32(TotalRsTaxes.Text), txtDate.Text, txtTime.Text, txtVerifierName.Text, txtAgentName.Text, lblRecordAdded, lblError);
                
                }
           
        }
        catch (Exception exe)
        {
            lblError.Visible = true;
            lblError.Text = exe.Message;
        }

 public void ADD_HOME_PHONE_DETAIL(string ArgPhoneLine, string ArgCallingFeatures, string ArgAddOn, string ArgLDPlan, string ArgConnectionCharges, string ArgAcctNumber, int ArgTotalAmount, string ArgSaleDate, string ArgSaleTime, string ArgVerifierName, string ArgAgentId,Label ArgRecrodAdded,Label ArgError)
    {
        try
        {
            MyConnection con = new MyConnection();
            cmd = new SqlCommand();
            cmd.Parameters.Clear();
            cmd.Connection = con.con;
            cmd.Connection.Open();


            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "ADD_HOME_PHONE_INFO";


            SqlParameter phoneline = new SqlParameter("@phoneline", SqlDbType.VarChar);
            SqlParameter callingfeature = new SqlParameter("@callingfeature", SqlDbType.VarChar);
            SqlParameter addon = new SqlParameter("@addon", SqlDbType.VarChar);
            SqlParameter longdistanceplan = new SqlParameter("@longdistanceplan", SqlDbType.VarChar);
            SqlParameter connectioncharges = new SqlParameter("@connectioncharges", SqlDbType.VarChar);
            SqlParameter acctnumber = new SqlParameter("@acctnumber", SqlDbType.VarChar);
            SqlParameter totalamount = new SqlParameter("@totalamount", SqlDbType.Int);
            SqlParameter saledate = new SqlParameter("@saledate", SqlDbType.SmallDateTime);
            SqlParameter saletime = new SqlParameter("@saletime", SqlDbType.SmallDateTime);
            SqlParameter verifier = new SqlParameter("@verifiername", SqlDbType.VarChar);
            SqlParameter agentid = new SqlParameter("@agentid", SqlDbType.VarChar);

            cmd.Parameters.AddWithValue("@phoneline", ArgPhoneLine);
            cmd.Parameters.AddWithValue("@callingfeature", ArgCallingFeatures);
            cmd.Parameters.AddWithValue("@addon", ArgAddOn);
            cmd.Parameters.AddWithValue("@longdistanceplan", ArgLDPlan);
            cmd.Parameters.AddWithValue("@connectioncharges", ArgConnectionCharges);
            cmd.Parameters.AddWithValue("@totalamount", ArgTotalAmount);
            cmd.Parameters.AddWithValue("@acctnumber", ArgAcctNumber);
            cmd.Parameters.AddWithValue("@saledate", ArgSaleDate);
            cmd.Parameters.AddWithValue("@saletime", ArgSaleTime);
            cmd.Parameters.AddWithValue("@verifiername", ArgVerifierName);
            cmd.Parameters.AddWithValue("@agentid", ArgAgentId);

            if (cmd.ExecuteNonQuery() > 0)
            {
                ArgRecrodAdded.Text = "RECORD IS SUCCESSFULLY ADDEDD...";
            }
            
        }
        catch (Exception exe)
        {
            ArgError.Visible = true;
            ArgError.Text = exe.Message;
        }
   
JAVA SCRIPT CODEING IS HERE 


function Validations()
	{
	if(document.getElementById("txtVerifierName").value=="")
	{
	alert("PLEASE ENTER VERIFIER NAME..");
	return false;
	}
		
	if(document.getElementById("chkHomePhone").checked==false)
	{
	alert("PLEASE SELECT HOMEPHONE CETEGORY");
	return false;
	}
	}

<asp:Button ID="btnAdd" runat="server" Text="ADD" OnClientClick="return Validations()" onclick="btnAdd_Click"  />

HERE IS THE CALCULATION CODING IN JAVASCRIPT

function Calcaulate()
    {
       if(document.getElementById("txtRegularRs").value=="")
       {
       alert("REGULAR TEXT IS EMPTY PLEASE ENTER VALUES");
       return false;
       }
       
       if(document.getElementById("txtLdPlanRs").value=="")
       {
       alert("LD PLAN TEXT IS EMPTY PLEASE ENTER VALUES");
       return false;
       }
       
      var txtRegular= document.getElementById("txtRegularRs").value;
      var txtLDPlan=document.getElementById("txtLdPlanRs").value;
       
      document.getElementById("txtTotalRegularRs").value=parseFloat(txtRegular)+parseFloat(txtLDPlan);
       
      document.getElementById("TotalRsTaxes").value=parseFloat(txtRegular)+parseFloat(txtLDPlan)+parseFloat(3.63);


<input type="button" value="CALCULATE" onclick="Calcaulate()"/>

THIS IS TOTAL CODING OF MY CURRENT PROJECT PLZZ HLP

b'coz javascript run on client side ok
when you press server button code it will postback to the server?
the question is how to know server client side calculation that you perfom with javascript?
Only one solution?

you have to make one static variable at server side this static variable is class level ok

you can use raisecallbackeventhandler interface and implement method in .cs file.

this means when you press html button whatever value calculate it will passed on server side static variable.


Assign static varible
private static int Value;

use code on page load :


String cbReference =
Page.ClientScript.GetCallbackEventReference(this,
"arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);

you must implement Icallback event handler interface

Like
public partial class NewsDetails : System.Web.UI.Page,ICallbackEventHandler

Implement method in same .cs
public String GetCallbackResult()
{ return "true"; }
public void RaiseCallbackEvent(String eventArgument)
{
value = eventArgument;
}

after write javascript

whatever calculation is made
Pass javascript through

Like

CallServer("YourNewCalculateValue","");

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.