Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Usually in asp.net, when you set the visibility of a control as false. then that control will not be shown in the aspx page when it renders. The control and its value is not available for any javascript function since the control is not rendered.
dropdown1.Visibility = False;

Say for example there is a dropdown with a value and the control visibility is false.
But i want the control's selected value to perform some validation inside a javascript function.
Is there any way to access the hidden control's id or value in javascript.

[Condition : No hidden field should be used to store the hidden control's value]
Posted
Updated 25-May-11 19:58pm
v3
Comments
Sandeep Mewara 19-May-11 2:22am    
You mean, that you need to find all the controls on the page that are hidden?

OR

you want to access a given hidden field in JS?
suren.info 19-May-11 6:04am    
I have a dropdown which is hidden, but i have to do some functionality with the the dropdown selected value in javascript.

1 solution

Well, you can easily workout on this issue.

What you must have done is used 'Visible=false' as one of the attribute on dropdown. This would not just hide but also let the control not participate in page rendering. It will be completely missing and thus no accessibility even via JavaScript.

Instead, use style display property and all will be good.
//server side codes
myDropdown.Style.Add("display","none") // hides it but accessible via JS  

myDropdown.Style.Add("display","block") //shows it back

In JS, just pass on the ID and you will get access to the control to play.

Try!
 
Share this answer
 
Comments
suren.info 24-May-11 0:39am    
It Works :)
Sandeep Mewara 24-May-11 1:29am    
Good to know... :thumbsup:
Though, someone still did not liked the answer and voted 3! :)
suren.info 26-May-11 2:01am    
i voted 4 for it. :) If you keep the dropdown display as "block", then you cannot keep any control next to it on the same row. Instead use myDropdown.Style.Add("display","inline")
Sandeep Mewara 26-May-11 4:49am    
Thats ok. I was not being that specific, just wanted to convey the way to achieve it.

:)
Ashishmau 26-May-11 2:01am    
Good explanation.

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