You put the tag <script>
at the head of the page?
Because if put and trying to assign a value will not work even, occurs the following error:
Uncaught Typeerror: Cannot set Property 'value' of null
Because you have not loaded the page completely you will not be able to assign value to any element.
To solve this you can put the <script>
at the end of <body>
, example:
Page.aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<script>
document.getElementById("<%= HiddenField1.ClientID.ToString() %>").value = 'Token';
</script>
</asp:Content>
Code Behind:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(HiddenField1.Value.ToString());
}
I tried to do with request request.form["Maincontent_meuhiddenfield"]; and also returned "";
– Marco Felipe
Try
Request.Form["ctl00$MainContent$meuHiddenField"]
– Maicon Carraro
I’ve tried that too and nothing; It’s very strange!
– Marco Felipe
What value does the
Request.Form.AllKeys
is coming?– Maicon Carraro
ctl00$ConteudoPrincipal$tcNavegacao$tpPesquisa$hdnStatus
– Marco Felipe
His field is the
hdnStatus
? If it is you need to doRequest.Form["ctl00$ConteudoPrincipal$tcNavegacao$tpPesquisa$hdnStatus"]
– Maicon Carraro
Funcionouuuuuuuu I found out. was analyzing the code here I noticed that was calling the button click before assigning the value to hiddenField hehe.
– Marco Felipe
Quiet, thanks for the return!
– Maicon Carraro