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

i need add the text box values defaultly

one doubt for this as per in sql statement, all fields must be need values. if one field value not enter valur show in error message. how to resolve this error.

txtOSITotalIncome.Text =  txtOSIInterstFromBank.Text + txtOSIInterestFromDebent.Text+txtOSIAccuredInterstOnNSC.Text
txtOSITotalTDS.Text = txtOSITDSFromBank.Text+ txtOSIAccuredInterstOnNSC.Text

how to get the these sums in textboxes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class OtherSourceIncome : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnOSI_Save_Click(object sender, EventArgs e)
        string connection = System.Configuration.ConfigurationManager.ConnectionStrings["itax"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand("INSERT INTO other_source_income VALUES ('" + txtOSIInterstFromBank.Text + "','"
            + txtOSITDSFromBank.Text + "','"
            + txtOSIInterestFromDebent.Text + "','"
            + txtOSITDSFromNSSWithdr.Text + "','"
            + txtOSIAccuredInterstOnNSC.Text + "','"
            + txtOSITotalIncome.Text + "','"
            + txtOSITotalTDS.Text + "','"
            + txtOSISalary.Text + "','"
            + txtOSIProfessionalTax.Text + "','"
            + txtOSIPFDeduction.Text + "','"
            + txtOSITDS.Text + "')", con);

Updated 11-May-12 5:20am
jdarknight 11-May-12 5:26am    
Is this your problem?

You want to automatically calculate the values for txtOSITotalIncome , txtOSITotalTDS if some other text box's values are entered.
2011999 11-May-12 5:28am    

1 solution

Make use of javascript to calculate the values.

Here is piece of example make use of this. i have used

to calculate txtTotal.

I have used the onBlur event in the textbox so that when the focus is out from the textbox the calculate function will be called.

This is my code in aspx page.

<html xmlns="">
<head id="Head1" runat="server">
    <script type = "text/javascript">
        //This is the javascript function which will calulate the total
        function calculate() {

            var sub1 = document.getElementById('txtSubject1').value; // specify the subject1 text box id value
            var sub2 = document.getElementById('txtSubject2').value; // specify the subject2 text box id value
            var sub3 = document.getElementById('txtSubject3').value; // specify the subject3 text box id value

            if (sub1 == '') sub1 = 0;
            if (sub2 == '') sub2 = 0;
            if (sub3 == '') sub3 = 0;

            var total = parseInt(sub1) + parseInt(sub2) + parseInt(sub3);

            document.getElementById('txtTotal').value = total;

<body onload="OnSuccess();">
    <form id="form1" runat="server">

        <asp:Panel runat="server" id="Panel2" style="display:block; width:718px;" >

        <td class="style1" style="width: 281px"> subject1:
        <asp:TextBox ID="txtSubject1" runat="server" onBlur="return calculate();" ></asp:TextBox>
        <td style="width: 458px">
            <br />
        <asp:TextBox ID="txtSubject2" runat="server" onBlur="return calculate();" ></asp:TextBox>
        <td style="width: 458px">
            <br />
        <asp:TextBox ID="txtSubject3" runat="server" onBlur="return calculate();" ></asp:TextBox>
        <td style="width: 458px">
            <br />
        <asp:TextBox ID="txtTotal" runat="server"></asp:TextBox>


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