views:

118

answers:

1

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?

+1  A: 

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.

Darin Dimitrov
@Darin: does the ID lblName the same as html input name? I'm trying to pass these values to a payment gateway.
eibhrum
Yes it is the same but ASP.NET could mangle the names and IDs of server side controls.
Darin Dimitrov