Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill a Label.Text - Property via jQuery

Tags:

I use ASP.NET and have a label control on my page, which I fill with the jQuery-Command

$('#<%= myLabel.ClientID %>').html(content); 

.val() does not seem to work with this.

Somehow, I have Problems getting the content in code-behind. In the code, the myLabel.Text-Property is still empty.

like image 696
AGuyCalledGerald Avatar asked Mar 22 '10 14:03

AGuyCalledGerald


People also ask

How to get label value in jQuery dynamically?

$(document). ready(function() { $("input[type=checkbox]:checked"). click(function () { var values = $("input label"). map(function () { return $(this).

How to create label dynamically in jQuery?

var label = $("<label>"). attr('for', "from"); label. html('Date: ' + '<input type="text" id="from name="from" value="">'); $(function() { $("#from"). datepicker(); });


1 Answers

If you want to display the value on the client and have it available on the page, you need an input that'll get sent to the code-behind when you POST like this:

$('#<%= myLabel.ClientID %>').html(content); $('#<%= myInput.ClientID %>').val(content);  <asp:Label Id="myLabel" runat="server" /> <asp:HiddenField ID="myInput" runat="server" /> 

In the code-behind:

myInput.Value 
like image 166
Nick Craver Avatar answered Oct 21 '22 10:10

Nick Craver