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 931307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:28:41+00:00 2026-05-15T20:28:41+00:00

I am trying to display a new panel after the user clicks an add

  • 0

I am trying to display a new panel after the user clicks an add button, for some reason this is not working (it refreshes the page as well, even though my button has a return true) I have tried different ways, but nothing seems to work that well.

<asp:Button ID="btnAdd" runat="server" Text="Add Property" CssClass="btn" OnClientClick="addProperty(); return false;"  />


 <script type="text/javascript">
    var num = 1;
    function addProperty()
    {
    num++;
    var panelName = "<%=pnlProperty"  + num.toString() + ".ClientID%>";
    alert(panelName);
    document.getElementById(panelName).style.display="inline";

    }
        </script>

Any helps would be great!

  • 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-15T20:28:42+00:00Added an answer on May 15, 2026 at 8:28 pm

    You cannot interact javascript and ASP.NET like that. ASP.NET will always execute before the code is being sent to the client, where the javascript executes. You can use .NET to generate javascript.

    In your case, this will execute before anything else:

    <%=pnlProperty" + num.toString() + ".ClientID%>
    

    It will not execute in a loop, because it is executed as ASP.NET code before the loop is generated and sent to the client. Nor will the value of the javascript variable num be used to create a panel, because javascript hasn’t started executed. Everything within <%, … %> will be interpreted as .NET code. So .NET will simply throw an error, because the above is not an accurate line of code.

    You need to write your .NET code so that it generates meaningful javascript.

    You could do something like this:

    var panels = [
       "<%= pnlProperty0.ClientID %>",
       "<%= pnlProperty1.ClientID %>",
       "<%= pnlProperty2.ClientID %>"
    ];
    

    … which might generate javascript that looks something like

    var panels = [
       "ctl00_main_pnlProperty0",
       "ctl00_main_pnlProperty1",
       "ctl00_main_pnlProperty2"
    ];
    

    … which is an entirely accurate way of creating an array of strings that you can then use in your javascript

    document.getElementById(panels[num]).style.display="inline";
    

    If you want a dynamic loop, you may have to do something like

    var panels = "<%
        String.Join(
            ",",
            Page.Controls.OfType<Panel>()
                         .Where(panel => panel.ID.StartsWith("pnlProperty"))
                         .Select(panel => panel.ClientID).ToArray());
    %>";
    

    … which might create something like

    var panels = "ctl00_main_pnlProperty0,ctl00_main_pnlProperty1,ctl00_main_pnlProperty2";
    

    upon which you could then do:

    var panelNames = panels.split(',');
    document.getElementById(panelNames[num]).style.display="inline";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm trying to add a control(Label) inside of a panel. Please see the code:
I am trying to display a panel with a BorderLayout. The panel being displayed
I am trying to create a help panel for an application I am working
I'm trying to make a tabbed user interface using an asp:Panel and the asp:TreeView.
I'm trying to add an array of labels to a panel in my Form.
I am actually trying to display a new controller of type UIViewController MKMapViewDelegate in
I'm trying to display an update progress loading image whenever my update panel does
I am trying to link some user docs to my Java Swing application. The
I'm trying to force the jqueryUI autocomplete's panel/list to at least display a default

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.