Reputation: 61
I have the following label in vb.net:
<div style="height: 20px; vertical-align: text-bottom;">
<div style="float: left; width: 86%; text-align: right">
<b>Sub-Total</b> (a) through (e) above:
</div>
<div style="float: right; padding-right: 10px">
<asp:Label runat="server" ID="lblRateableEmployeesSubtotal" CssClass="lblRateableEmployeesSubtotalCls" Text="0"></asp:Label>
</div>
</div>
And I am dynamically adjusting this value in from a javascript function:
$('.lblRateableEmployeesSubtotalCls').text(numberWithCommas(subtotal));
This function is called whenever certain textboxes are changed. numberWithCommas just formats the text into a number format (x,xxx).
When I am trying to save these values in my codebehind, for some reason the labels' text is still showing as "0"! Even though it is clearly updated on the screen.
If lblRateableEmployeesSubtotal.Text > "" Then .TotalEmployees = CInt(lblRateableEmployeesSubtotal.Text)
Any idea why this could be happening?
Upvotes: 0
Views: 1061
Reputation: 963
That jQuery function only changes the text on the client, server doesn't know anything about any changes to the page until you send a POST request, but in that request by default only values of the INPUT elements are sent.
If you want to alter some things on the server using javascript on the client you're looking for the AJAX technology. If not, consider obtaining the value on the server from an input control like text box or make some hidden fields which will be updated in the same time as your label.
Sorry for my english.
Upvotes: 0
Reputation: 203811
ASP doesn't bother to include this information when it performs a postback, specifically because the whole idea of a label isn't to accept input from the client. When posting back ASP doesn't send the entire DOM; it only sends the information for fields specifically designed to accept input from the client.
In this case, the appropriate tool to use here is a Hidden
control. Add an asp:HiddenField
control to the page, set that control's value in your JavaScript code (you can set the label too, of course) and then inspect the value of the hidden field on the server side.
Upvotes: 1
Reputation: 39777
Only Input-type controls are posted back to the server. One possible solution in your case is simulate label with read-only flat-styled TextBox control.
Upvotes: 0