views:

23

answers:

1

Hi,

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.

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

+2  A: 

You can just put runat="server" on the control to access it from your code behind:

<input type="hidden" name="reference" id="reference" runat="server" />

Then, in your code behind:

void Page_Load(object sender, EventArgs e)
{
    // ...

    reference.Attriutes["value"] = "any values I want";

    // ...
}

Note that in this case, the "id" attribute is required because when you have runat="server", the id attribute is used to specify the name of the generated variable.

Dean Harding
Actually you don't need the Attributes property. Since ASP.NET makes it a type HtmlInputHidden control when you add the runat="server" you can directly write: `reference.Value = "any values I want";`For more information: http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlinputhidden(VS.80).aspx.
XIII