I like to add a validation on a label based on its visibility, in that a submit button will raise a validation message or error if the label is not visible.
I am used to the validation controls in the Toolbox, which wont allow this functionality!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It seems as though if an asp:Label’s visibility is set to false, the asp.net engine will not even put it in the DOM. So you can check in javascript, using the
onclickproperty of the (html) button to check if the label is in the DOM or not, and use asp.net’s__doPostBack()javascript function to post back to the server if it is there:To be completely honest, I thought the
lblwould beundefinedif the label did not exist in the DOM, but Firebug revealed it is actuallynull. Anyway, a couple things to note is that in order for asp.net to define the__doPostBack()method, I believe you need some control in the form that hasautopostback="true", and in the code-behind you can check what caused the postback in thePage_Loadmethod like so: