Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,
I want to get the hiddenfield value in masterpage (pageload event).
I assigned the hiddenfield value in javascript by following code.
function GetNavigationId(id) {
     document.getElementById('<%=hdNavicationText.ClientID %>').value = id;
     var text = document.getElementById('<%=hdNavicationText.ClientID %>'); 
     alert(text.value);
  }


This script was working correctly.

But I cannot get the value of hidden field in pageload event and page Init event.

Javascript function alert box gives the exact value But In pageload I can get only null values.

I also try HiddenField hid1 = (HiddenField)Page.MainContent.FindControl("hid1");


What I have to do Please guide me?
Posted
Updated 26-Apr-13 3:14am
v2
Comments
sri senthil kumar 26-Apr-13 9:13am    
Are u not able to get the value for the first load or in next postback? because in first load only after server side code finishes execution js will run so you wont be able to get.
sri senthil kumar 26-Apr-13 9:36am    
Are you able to get the hiddenfield object in master page?
Member 8393790 26-Apr-13 9:48am    
yes,but the value is empty..

1 solution

This is happening because your child page will not be rendered as it is when used with master pages that is why Java script not able to find value.

Please do view source and find your hidden filed and see what is your hidden filed id .
.NET adds string like 'ctl00_hdnField' before your hidden filed name .

Where 'hdnhdnField' is your hidden file id and 'ctl00' is addend by asp.net.
so what you have to do is find your id and put in above way.

Example In JavaScript Coding

function Test()
{

alert(document.getElementById('ctl00_hdnField')value);

}
 
Share this answer
 
Comments
Member 8393790 26-Apr-13 9:23am    
when I do view source,the hidden filed like " <input type="hidden" name="ctl00$hdNavicationText" id="hdNavicationText" />" this. Id was same in hiddenfield and javascript function.. javascript working fine. but I cant get these hdn field value in masterpage page load.
Nilesh Rokade 3-May-13 5:24am    
can u share your some code ? not able to understand what you want to convey

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