Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using one hidden field, i will set value for that hidden field using javascrpt before page load. i want access that hidden field value code behind in page load.But it is showing empty.
Posted
Comments
Karthik Harve 27-Dec-11 6:24am    
before page load means on which event are you assigning the value to hidden field..??
Dines87 27-Dec-11 7:27am    
<input type="hidden" id="hdnMiddlediv" runat="server" />
<script type="text/javascript">
document.getElementById('<%=hdnMiddlediv.ClientID %>').value='test';

</script>

While page load i want access this value
Karthik Harve 27-Dec-11 6:42am    
Show some code.

either show some code, this will help me or you can print that in alert box to test that weather it is assigning the value or not.
or you can print that value on page.
 
Share this answer
 
Comments
Dines87 27-Dec-11 7:27am    
<input type="hidden" id="hdnMiddlediv" runat="server" />
<script type="text/javascript">
document.getElementById('<%=hdnMiddlediv.ClientID %>').value='test';

</script>

While page load i want access this value
JavaScript
<input type="hidden" id="hdnMiddlediv" runat="server" /> <script type="text/javascript"> document.getElementById('<%=hdnMiddlediv.ClientID %>').value='test'; </script> 

While page load i want access this value
 
Share this answer
 
v2
Comments
RaviRanjanKr 27-Dec-11 16:10pm    
[Edited]Normal texts removed from Pre tag[/Edited]
 
Share this answer
 
v2
Dines87 :

<input type="hidden" id="hdnMiddlediv" runat="server" /> <script type="text/javascript"> document.getElementById('<%=hdnMiddlediv.ClientID %>').value='test'; </script>
While page load i want access this value


It is clear that you will not see the value of this hidden field at first occurrence of page OnLoad because the order of execution is something like this :

page OnLoage (server) --- send output to client --->  client scripts run(hidden field is set here because it is a client side script) ---> page post back ---> page OnLoad (server)


To determine its a first OnLoad or it is not , use IsPostBack boolean variable in OnLoad event handler.

Hope it helps.
 
Share this answer
 
Hello,
Please try this code ..

ASP.NET
<input type="hidden" id="hdnMiddlediv" runat="server" />


JavaScript
<script type="text/javascript">
        window.onload = function () {
            document.getElementById('<%=hdnMiddlediv.ClientID %>').value = 'test';
        };

        $(document).ready(function () {
            if (document.getElementById('<%=hdnMiddlediv.ClientID %>').value = '')
            { document.getElementById('<%=hdnMiddlediv.ClientID %>').value = 'test'; }
        });
    </script></script>
 
Share this answer
 
Comments
CHill60 29-May-13 11:50am    
Why are you posting solutions to questions that are over one year old and already have solutions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900