0

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 Answer 1

1

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.

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

2 Comments

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

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.