abramlimpin
abramlimpin

Reputation: 5077

ASP.NET/HTML: Use ASP.NET's label text/value in HTML's input value

I have the following html codes (to be used in POST method):

// from Default.aspx
<input type="hidden" name="lblName" value="John" />
<input type="hidden" name="price" value="100.00" />

Is it possible to change the 'value' part by using the value/text ASP.NET label given below:

//from Default.aspx.cs
<asp:Label ID="lblName" runat="server" Text="John" />
<asp:Label ID="lblPrice" runat="server" Text="100.00" />

I just want to find a way to retrieve 'value' data dynamically coming from the ASP.NET label. Any suggestions?

Upvotes: 0

Views: 1395

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

Why not using a server side hidden control whose values could be modified dynamically from the server side:

<asp:HiddenField ID="lblName" runat="server" Value="John" />

Another possibility is to perform this on the client side using javascript: labels are usually rendered as span tags, so you will need to obtain the proper span by id and then assign it's innerHTML value to the hidden element. Using a javascript framework like jQuery might render this task much easier and guaranteed to work cross browser.

Upvotes: 1

Related Questions