Reputation: 99
I'm unable to get asp:label
value on server side which is set client-side in jQuery.
The small example is as below:
$("#btn1").click(function () {
$("#<%=prd1.ClientID %>").text("L1001");
});
Now I want it back in asp textbox by clicking another button:
protected void Button1_Click(Object sender, EventArgs e)
{
Test.text=prd1.text;
}
I'm trying to get back value of “prd1” in textbox “Test” but failed.
Any idea why?
Upvotes: 1
Views: 1673
Reputation: 312
Instead of using asp:label you can do is use a standard label tag and put runat="server" in that tag like
<label runat="server" id="temp_lbl"></label>
In jquery
$("#<%=temp_lbl.ClientID%>").html('Your Data Here');
In C#
string data = temp_lbl.Value;
Upvotes: 0
Reputation: 8545
There is no value associated with label. Use a asp hidden field instead.
<script type="text/javascript"src="Scripts/jquery-1.9.1.js"></script>
$("#btn1").click(function () {
$("#<%=hidden.ClientID %>").val("L1001");
});
protected void Button1_Click( Object sender, EventArgs e)
{
Test.text=hidden.Value;
}
Upvotes: 1