Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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 %>'); 

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 26-Apr-13 2:44am
Edited 26-Apr-13 4:14am
sri senthil kumar at 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 at 26-Apr-13 9:36am
Are you able to get the hiddenfield object in master page?
Member 8393790 at 26-Apr-13 9:48am
yes,but the value is empty..

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
so what you have to do is find your id and put in above way.

Example In JavaScript Coding

function Test()


Member 8393790 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 325
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200
0 OriginalGriff 465
1 Sergey Alexandrovich Kryukov 275
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200

Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100