Click here to Skip to main content
15,906,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi All ,
i have a problem with java script,
i am using 6 text boxes and one total text box,if i add the values to 6 text boxes it will increase and total shown in total text box and ill save all six text box values into database but total is not stored into database that is not needed , and my problem is if i update these values the total value is not shown in the total text box what is the code behind that plz tell me ASAP..


Thanks in advance
Posted
Comments
rkthiyagarajan 19-Sep-11 7:29am    
Enable autopostback is true.
hitech_s 19-Sep-11 7:44am    
first of all tell me where you are adding all the textbox values?
Ganesh_mca 19-Sep-11 8:18am    
Tabcontainer tabpanel3

You code behind (on Server-Side) does not recognize changes that are made by JavaScript (on Client-Side). To overcome this there's one of two things you can do:
1. Use hidden input field e.g.
ASP.NET
<input id="inputTotal" runat="server" type="hidden" />

Access your total:
C#
String myTotal = inputTotal.value;



2. Use ajax to transfer data without having to post back your entire page and there are many tutorials for that on google e.g.
http://www.tutorialspoint.com/ajax/[^]
 
Share this answer
 
Hi,

we can not access values changed by javascript in server side.

To overcome this you can use session variables to store required data.by this we no need to use database.

First we've to pass the changed data to server in asynchronous manner.

For better understanding 'm providing some example here..

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language="javascript" >
        function setval() {
            $("#TextBox1").text("hi this is testing");
            $.post("default3.aspx?action=change", {txt:"hi this is testing"}, function (data) { });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type ="button" value ="set Value" id="bthsetval" onclick="setval()" />
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>><br />
        <asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" />
    </div>
    </form>
</body>
</html>


In back you've to write some code for storing data in session variable

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.QueryString["action"] != null)
    {
        Session["lbltext"] = Request.Form["txt"].ToString();
    }

}
protected void Button1_Click(object sender, EventArgs e)
{
    if (Session["lbltext"].ToString() != "")
    {
        TextBox1.Text = Session["lbltext"].ToString();
    }
}


In this example I used jquery for posting data to server.Intead of that you can use basix asynchronous request for sending data to server.

I hope you understand what i said.

All the best
 
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