How to set value of <input type="hidden"> in asp .net page_load without using runat="server"

c#

Solution

I sometimes do the following, especially when I want control over my ids (especially when using jquery).

<asp:literal id="literal1" runat="server"><input type="hidden" id="someid" value="{0}"/></asp:literal>

Then, in codebehind you can set the value with the following:

literal1.Text = string.Format(literal1.Text, "somevalue");

This doesn't really get around using runat="server", but you haven't specified why you don't want to do that. Also, you'd have to get the value with a request.form

Update

In .net 4.0 you have much more control over your IDs. See this for more information:

http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx

Problem

i need to do the following two things... - i want to set value of in asp .net page_load. the problem is that i dont want to use runat="server". i have tried this the following but it does not work: HtmlInputHidden hiddenControl = (HtmlInputHidden) FindControl("a"); is there a way to access in asp .net page_load without using runat="server"? ? ? - i can do this if i use but in this case i cannot access it in master page's javascript function. i have tried this but it does not work... - var hdnField = document.getElementById('<%= hdnIdentity.ClientId%>'); - var hdnField = document.getElementById("hdnIdentity").getAttribute("value"); - var hdnField = document.getElementById("hdnIdentity").value what i need... i want to access content page's hidden field value in javascript in master page. is there a way ? ? ? thnx in advance regards Haroon haroon426@yahoo.com

Original source