[RESOLVED]I am trying to add a hiddenfield dyamically with the name being a variable. What am I doing wrong wtih the folllowing?

If I use:

 function contentPageLoad() {
strText = '<asp:HiddenField ID="test" runat="server" Value="Block;absolute;0px;0px" />' 
strAppend = strText.toString(); }

It works fine.  But trying to feed the ID in as a variable as in the following, I get  "server tag not wellformed when loading.
function contentPageLoad() {
var test = "test"; strText = '<asp:HiddenField ID="' + test + '" runat="server" Value="Block;absolute;0px;0px" />' strAppend = strText.toString();
}


You can’t use server controls like that.  Just use a normal <input type=hidden id="test" name="test"> tag instead.  You can retrieve the value server-side using

Request.Form["yourHiddenFieldName"]

Thanks where do I store the value part of a hiddenfield in the input tag? 

<input type="hidden" name="mydata" id="mydata" value="data goes here"/>

Thanks, worked perfectly!

Leave a Reply