Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  199] [ 5]  / answers: 1 / hits: 8990  / 11 Years ago, thu, february 13, 2014, 12:00:00

I have a hidden field that I set in my javascript code:



   <script type=text/javascript>

function start() {
document.getElementById('Hidden1').value = somme value;
}
</script>

<body>

<form id=form1 runat=server>
<div>
<input type=text id=Hidden1 name=Hidden1 runat=server/>
<div>
</form>


In my code behind I want to get the input value in my page_load function:



  protected void Page_Load(object sender, EventArgs e)
{
if (!Page.ClientScript.IsClientScriptBlockRegistered(start) && !IsPostBack)
{

Page.ClientScript.RegisterStartupScript(typeof(Page), start, start();, true);

}
string message =Hidden1.Value;
}


The message is empty, how can'I get the hidden value in my page_load?



Thanks.


More From » c#

 Answers
1

You are not submitting the page back to the server, you won't be able to get page variables unless you are doing a POST.



change this:



<form id=form1 runat=server>
<div>
<input type=text id=Hidden1 name=Hidden1 runat=server/>
<div>
</form>


to this: (EDIT: changed the type=hidden too)



<form id=form1 runat=server>
<div>
<input type=hidden id=Hidden1 name=Hidden1 runat=server/>
<div>
<input type=submit value=submit />
</form>


Then click the submit button


[#47756] Thursday, February 13, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kendellc

Total Points: 84
Total Questions: 97
Total Answers: 102

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;