Click here to Skip to main content
Rate this: bad
good
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 %>'); 
     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 26-Apr-13 2:44am
Edited 26-Apr-13 4:14am
Bojjaiah6.1K
v2
Comments
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
good
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 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);
 
}
  Permalink  
Comments
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 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
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