You must Sign In to post a response.
  • Category: ASP.NET

    How To Pass Label Value in from Jquery(Client Side) to Server Side (Code behind)

    Hi Developers,

    how to pass TextBox & Label Value from Client side Jquery to Derver Side(Code Behind).
    I have done some of modules using jquery Running time.
    But the Running time Label Values are Not Bind in Server Side. ald also cant able to insert that runtime value.(Label.Text=Null).

    My Jquery Runtime:

    Am using onkeyup="txtpercentage()"
    <script>
    function txtpercentage() {

    var Total= $("#txtGrandTotal").val();
    var Already = $("#txtAlreadyPaid").val();
    Balance = parseFloat(Total) - parseFloat(Already );
    $("#lblBalance").html(Balance.toFixed(2));

    }
    </script>

    Html Form:

    <table>

    <tr>
    <td>
    <asp:Label ID="Label36" runat="server" Text="Grand Total"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:Label ID="txtGrandTotal" runat="server" class="add"
    AutoComplete="off" Width="250px"></asp:Label>

    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label38" runat="server" Text="Already Paid"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:TextBox ID="txtQUOTEAlreadyPaid" runat="server" AutoComplete="off" Width="250px"
    onkeyup="txtpercentage()"></asp:TextBox>


    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label37" runat="server" Text="Balance Payment"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:Label ID="lblBalance" runat="server" AutoComplete="off" Width="250px" Font-Bold="true"></asp:Label>

    </td>
    </tr>
    </table>

    in my query is working fine with functionalities.
    But i cant able to get Label(lblBalance) Text or Value .
    So still i cant able to insert Label(lblBalance ) value into the database.
    because in server side lblBalance.Text is showing Null.

    So How i am get the label values and insert it. any suggestion.
    if Possible how to Pass Label(;b;Balance) value to Server side to a Button Click

    thanks with
    Paul.S
  • #767051
    You can write even Javascript code in Jquery like
    VAR BALANCE = YOUR MANIPULATIONS

    document.getElementById('lblBalance').value = balance.toFixed(2)

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #767052
    Following are some the tips to find the issues
    1. Try to use the "text" for assign the values into the label. See the below code

    function txtpercentage() {
    var Total= $("#txtGrandTotal").val();
    var Already = $("#txtAlreadyPaid").val();
    var Balance = parseFloat(Total) - parseFloat(Already );
    $("#<%=lblBalance.ClientID %>").text(Balance.toFixed(2));
    }


    2. Where you are trying to get the values?
    Are you initializing the the value of "lblBalance.Text " in the page load?
    If your doing any initialization in the page load, keep those values inside "IsPostBack" check.

    By Nathan
    Direction is important than speed

  • #767054
    Nathan,
    var keyword should be there in Balance declaration ?

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #767063
    Hi Paul,

    If you are assign some value to your controls like textbox or label, those values should be reflected back automatically in your server side code once you call the text property of the control.

    Ex:

    txt1.Text;

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767067
    You are right Mr.Naveen but in this case the value does not reflected in Server Side.

    Am using Jquery for Text and Label values changing on runtime.
    so there this may cause of this Problem ..?

  • #767068
    There are multiple ways to pass value from client side to server side
    1. using hidden fields

    //take hidden field
    < asp:HiddenField ID="hdnfldVariable" runat="server" />
    //add value in it using javascript
    < script type="text/javascript">
    var somefunction = function () {
    var hdnfldVariable = document.getElementById('hdnfldVariable');
    hdnfldVariable.value = 'value from javascript';
    }
    < /script>
    //on code behind access it
    string variable = hdnfldVariable.Value;

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments