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

  • SEARCH
  • Home
  • 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 6688443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:24:18+00:00 2026-05-26T05:24:18+00:00

i’m really sorry if this question have been asked before but I couldn’t find

  • 0

i’m really sorry if this question have been asked before but I couldn’t find it.

Working on a ASP.NET/C# web application.

i am creating a label in the code behind and adding it to the page (all coded in the code behind and not in design page)

Now I have a check-box I want to change the visibility of the label depending if the checkbox is checked (show) or if not (hide).

I tried to use an update panel. But since the label is generated in code I have to generate it again everytime there is a partial postback. and I don’t want that.

Is there a way to do this with javascript to avoid post-backs? other solutions are also appreciated.

Thank you very much for any help

  • 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-05-26T05:24:19+00:00Added an answer on May 26, 2026 at 5:24 am

    You are on the right track. You can avoid the overhead and complexity of using UpdatePanel controls and an AJAX call by using client-side script to do this instead.

    You’ll want to define a JavaScript function to fire for the onClick event of the checkbox on your web page:

    <input type="checkbox" onclick="checkboxChanged(this);" />
    

    I’ll assume you’re adding a label with ID “lbl” to the page from your code-behind. Make sure you make the label a Protected member of the Page class so you can access it from the aspx page using a server tag to retrieve the correct ID for when you call document.getElementById in JavaScript. This is important.

    Partial Class MyPage
      Inherits System.Web.UI.Page
      Protected lbl As Label
    
      Private Sub Page_Load(sender As Object, e As EventArgs)
    
        If Not Page.IsPostback Then
    
          lbl = New Label()
          lbl.ID = "lbl"
          Me.Controls.Add(lbl)
    
        End If
    
      End Sub
    
    End Class
    

    So here’s what your JavaScript code on your aspx page will look like:

    function checkboxChanged(checkbox) {
      if (checkbox.checked) {
        document.getElementById("<%=Me.lbl.ClientID %>").style.display = 'inline';
      } else {
        document.getElementById("<%=Me.lbl.ClientID %>").style.display = 'none';
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.