Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:58:07+00:00 2026-06-08T11:58:07+00:00

I like to add a validation on a label based on its visibility, in

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:58:09+00:00Added an answer on June 8, 2026 at 11:58 am

    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 onclick property 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:

          <script type="text/javascript">
            function testMe()
            {
              var lbl = document.getElementById('lblTest');
              if(lbl == null)
                document.getElementById('msg').innerHTML = "Error";
              else
                __doPostBack('testButton');
            }
          </script>
          <asp:Label ID="lblTest" runat="server" Visible="false" Text="Hello"></asp:Label>
          <button onclick="testMe();">test</button>
    

    To be completely honest, I thought the lbl would be undefined if the label did not exist in the DOM, but Firebug revealed it is actually null. 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 has autopostback="true", and in the code-behind you can check what caused the postback in the Page_Load method like so:

    if(Request.Form["__EVENTTARGET"] == "testButton") {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to create template for string, that will include label, textbox with watermark
What I would like to do is have a standard error message that uses
I've designed a domain model following DDD methodology. I would like to add validation.
I would like to kwnow if it possible for users to add validation rules
I have a simple form and would like to add a custom jQuery validation
I like the Add Connection or SQL Connection dialog that is in Visual Studio
I have a DateTime TemplateEditor and I would like to add regex validation to
I would like to add some data validation on a cell in the latest
in MVC3 you can add validation to models to check if properties match like
my droDownBox look like: add(new DropDownChoice<String>(hladaneSlovo, new HladaneSlova()).add(new AjaxEventBehavior(onchange) { private static final long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.