Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi every body,

In my asp.net page i have Hiddenfield control,
and i want to use the id of this control in client side code by using javascript and in sever side code by c#.

the problem is that:

to use the id of Hiddenfield control in client side code by using javascript i must not used the property of runat = "server",

and to use the id of Hiddenfield control in server side code by using c# i must using the property of runat = "server"

as when i using runat property i cannot use the control by javascript like:

JavaScript
document.getElementById("hdSaveHtml").value = "any thing"; 


it give me null.

my asp.net page has master page and this master page has another master page and all are inside folder in the project
Posted
Updated 3-Oct-11 0:20am
v4
Comments
kiran dangar 3-Oct-11 9:23am    
Hi, can you explain what kind of trouble you are having after trying all solutions below.. If possible paste your aspx file coding as well..

you can access server control from javascript like this

<asp:HiddenField ID="hdSaveHtml" runat="server" />

document.getElementById('<%=hdSaveHtml.ClientID %>').value="0";



in code behind you can access like normal control
 
Share this answer
 
v2
Comments
P.Salini 3-Oct-11 3:14am    
My 5!
MrLonely_2 3-Oct-11 3:46am    
I try that but not help, sorry.
hitech_s 3-Oct-11 6:57am    
provide your .aspx code ,i will try my level best
Try to query for the ClienID in your javascript code.

document.getElementById("ct100_ContentPlaceHolderName_hdSaveHtml").value = "any thing";


Best regards
 
Share this answer
 
Comments
MrLonely_2 3-Oct-11 3:47am    
I try that but not help, sorry.
the id is ctl00_ctl00_MainContent_OperatorContent_hdSaveHtml
Use JQuery and life will be simple

just write this way
HTML
var DisId = $('#hdnDisId').val();
 
Share this answer
 
Comments
MrLonely_2 3-Oct-11 3:47am    
not help too
Anuja Pawar Indore 3-Oct-11 6:36am    
Place your code, as it should work, whether u have master page or control inside a master page
Use the view source option in your browser, findout the correct id for the hidden field you are using in your page, as you are using a master page the id for the hidden control changes . Copy paste the id you found in your page source for hidden control to your javascript.
 
Share this answer
 
v2
Comments
MrLonely_2 3-Oct-11 3:48am    
the problem still and id is ctl00_ctl00_MainContent_OperatorContent_hdSaveHtml

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