I am trying to integrate with a payment gateway. They require a set of hidden input boxes to be posted to their gateway like:
<input id="orderref" name="orderref" type="hidden" runat="server"/>
I have added runat=”server” so I can dynamically populate the boxes with values.
However, of course at runtime the input box name gets changed to:
<input name="ctl00$ContentPlaceHolder1$orderref" type="hidden" id="ContentPlaceHolder1_orderref" value="9" />
I’m in a catch 22. If I remove runat=”server” all is fine with regards to the name, but I then can’t populate the input box with values! Is there a means to force the name of the field to stay the same?
Depending on what .NET version you are using the control over this differs: basically, pre-.NET4 you can only alter the container prefix by implementing your own, but from .NET4 you can omit the container prefixes using
ClientIDMode.Alternatively, you may expose methods, say, on your page or master page and then call them using inline-scripting (
<%=MyMethodReturningValue() %>) which is evaluated at the time of render.EDIT:
To elaborate a little on my second suggestion, you can define a method in your pages code-behind that can be executed in an inline manner by use of embedded code blocks; the referenced link gives simple examples of this, but the methods needn’t be in
<script>blocks of the page itself (as I previously touched on) so that you can keep your logic separated, such as:Define a method in your page’s code-behind:
Write out your
inputelement, omitting therunatattribute, and adding the embedded code block in place of where the value would be (think of this as a place holder); this code block is going to call the specified method on pre-render, and essentially be replaced by the returning value: