tags:

views:

20

answers:

1

I have an asp.net page and I'm trying to add a couple of hidden HTML input controls. I will be submitting this form to another site (PP) so I need the names of the controls to NOT change when rendered. Is there a way to make ASP.NET honor the name property that I set in the code-behind?

As an alternate, I don't need to dynamically create these controls, I can also just assign the value to an existing HTML field but I don't know how to do that with ASP.NET/C#

A: 

Are you using ASP.NET 4.0? You can use ClientIDMode on the control with a value of static, and the ID will not change.

Otherwise you could use a literal to output the element itself or just its value. On you're page you'd have:

<input type="hidden" id="ppID" value='<asp:Literal ID="ppIDValue" runat="server" />' />

or

<input type="hidden" id="ppID" value="<%= ppIDValue %>" />

And in the code behind or wherever:

this.ppIDValue.Text = "value for ppID";

or (abbreviated):

public class MyPage : Page
{
    public string ppIDValue = "0";
    override OnLoad()
    { this.ppIDValue = "100"; }
}
s_hewitt
Im using ASP.NET 3.5. Can you give an example of the literal output?
Jim Beam
Thank you! Just what I needed
Jim Beam