5

i have a @Html.Label("", new { id="txtStatus1" })

where txtstatus1 value is obtained using jquery as $('#txtStatus1').val(TicketStatus);

but im not able to set this value to label .

1
  • 1
    try .text() instead of .val() Commented Dec 9, 2013 at 11:21

2 Answers 2

10

This statement does not output anything as you have not specified a for value:

@Html.Label("", new { id="txtStatus1" })

If you change it to give it a value i.e.

@Html.Label("a", new { id="txtStatus1" })

It outputs this:

<label for="a" id="txtStatus1">a</label>

Sridhar R is correct you can use text to set it like this:

$('#txtStatus1').text('this')

http://jsfiddle.net/bk8KZ/

You might need to add quotes and output around the argument if it is comming from your model i.e.

$('#txtStatus1').val('@Model.TicketStatus');

What is TicketStatus exactly?

Sign up to request clarification or add additional context in comments.

1 Comment

ticketstaus is a variable to set value.I solved the problem by using <p id="qqq"> where $('#qqq').text(variable);
5

Try this

Use .text() or .html()

Get html label value

var txt = $('#lbltxt').html();

Set html label value

$('#lbltxt').html("your value");

To get asp.net label value we need to write the code like as shown below

var txt = $('#<%=lbltxt.ClientID%>').html();

or

var txt = $("[id$='lbltxt']").html()

Set Asp.net label Value

$('#<%= lbltxt.ClientID%>').html('Your Value')

Or

$("[id$=' lbltxt']").html('Your Value')

1 Comment

I'm using html5 and MVC4 RAZOR setting query as $('#txtStatus1').text(TicketStatus); did not help !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.