abramlimpin abramlimpin - 2 years ago 131
HTML Question

HTML/ASP.NET: <input type="hidden" name="reference" value="ABC"/>

I just wanna ask if there's a possibility to change:

<input type="hidden" name="reference" value="ABC"/>

into this:

<input type="hidden" name="reference" value="any values I want"/>

where I can set any values behind .cs/C# - making it dynamically. The payment gateway I'm using requires and I can't find a way to included an ASP.NET control ( ?)
and I'm needing your suggestions/comments about it. Thanks.

<asp:HiddenField ID="reference" runat="server" Value="ABC" />
is not working because the payment gateway specifically needs the 'name' property.

Answer Source

I know this is an old post, but for anyone looking to solve this issue now - If you add runat="server" to the input, the name will be changed (e.g. MainContentArea_ctl00_ctl01_ctl01_amount). ClientIdMode="Static" will only help for the ID. To get around this:

In your html page use a Literal :

    <asp:Literal runat="server" ID="litInputAmount"></asp:Literal>

In the code behind file, assign a string to the Text attribute of the Literal This string should be the html as you would like it to be. The correct value can also be added for the value field:

    litInputAmount.Text = String.Concat("<input id='inputAmount' type='hidden' name='amount' value='", Price.ToString(), "'>");

This will then be compiled as:

    <input id="inputAmount" type="hidden" value="224.4" name="amount">

This will give the information to the payment gateway with the correct name, but your value can be managed dynamically. Repeat for any other values that need to be added before sending.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download