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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:34:59+00:00 2026-05-24T08:34:59+00:00

So what I would like to do is something I see pretty frequently on

  • 0

So what I would like to do is something I see pretty frequently on webforms etc., basically in my webform I want to grant the user the ability to add more information as is necessary. For example I ask for a word but I want to allow the entry of multiple words by having a button to reveal an additional textbox each time it is clicked. Right now how I am trying to implement it is by creating 3 textboxes (and buttons corresponding to each one) leaving the first one visible but hiding the rest. The idea would be then that a global varible which track which textbox should be revealed and then I run a switch statement on that and reveal the appropriate box:

<asp:TextBox ID="textBoxNewCanonical" runat="server"></asp:TextBox>
<asp:Button runat="server" ID="buttonFind" Text="Find" Visible="false" OnClick="buttonFind_OnClick" />
<asp:TextBox ID="textBoxNewCanonical1" Visible="false" runat="server"></asp:TextBox>
<asp:Button runat="server" ID="buttonFind1" Text="Find" Visible="false" OnClick="buttonFind_OnClick" />
<asp:TextBox ID="textBoxNewCanonical2" Visible="false" runat="server"></asp:TextBox>
<asp:Button runat="server" ID="buttonFind2" Text="Find" Visible="false" OnClick="buttonFind_OnClick" />
<asp:Button runat="server" ID="btnMultipleCanonical" Text="Choose Another Canoical" OnClick="buttonChooseAnother_Click" />

and here is the buttonChooseAnother_Click

protected void buttonChooseAnother_Click(object sender, EventArgs e)
{
    switch(CanonicalNum)
    {
        case 0:
            textBoxNewCanonical1.Visible = true;
            buttonFind1.Visible = true;
            break;
        case 1:
            textBoxNewCanonical2.Visible = true;
            buttonFind2.Visible = true;
            break;
        default:
            break;
    }
    CanonicalNum = CanonicalNum+1;
}

CanonicalNum is set to 0 to start It seems like this should work but what ends up happening is when I click the button it just shows textBoxNewCanonical1 and then doesn’t do anything else the next time I click.
So my question is two-fold
1. Can anyone tell me what might be wrong with my code and how to fix it
2. If there is a better way to do it I would be happy to hear it

A couple things you might want to know is that I need to be able to access the buttons currently I also use a switch statement to handle them in one event handler. Also I need access to the text fields so that I can fill in a value upon another button click event.

Edit: Its a subpage of a Masterpage just fyi.

  • 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-24T08:34:59+00:00Added an answer on May 24, 2026 at 8:34 am

    The button click will cause postbacks, which will reset CanonicalNum to 0 when the page reloads. I would use Session to store CanonicalNum:

    In your page_load method, add this:

    if (!Page.IsPostBack)
    {
        CanonicalNum = 0;
        Session["CanonicalNum"] = CanonicalNum;
    }
    else
    {
        CanonicalNum = (int)Session["CanonicalNum"];
    }
    

    In your button click event, update the Session object with the new value after you increment CanonicalNum:

    Session["CanonicalNum"] = CanonicalNum;
    

    If you want the textboxes to stay visible, you’ll need to update your buttonChooseAnother_Click to handle this, otherwise the ones that don’t match CanonicalNum will be set back to Visible = “false” on postack:

    protected void buttonChooseAnother_Click(object sender, EventArgs e) 
    {     
    
        switch(CanonicalNum)     
        {         
            case 0:             
                textBoxNewCanonical1.Visible = true;             
                buttonFind1.Visible = true;
                break;         
            case 1:
                textBoxNewCanonical1.Visible = true;
                buttonFind1.Visible = true;             
                textBoxNewCanonical2.Visible = true;
                buttonFind2.Visible = true;             
                break;         
            default:             
                break;     
        }     
    
        CanonicalNum = CanonicalNum+1; 
        Session["CanonicalNum"] = CanonicalNum;
    
    }
    

    I think you may want to revisit what you’re trying to accomplish, as there’s probably a better way to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is something that I solved using reflection, but would like to see how
In jquery that is. I would like something that works as the success-pararameter, but
I would like to do something like this: abstract class Foo { public function
I would like to do something like this in HTML5 where I have something
I would like to recreate something like this if ( arg1 || arg2 ||
I would like to run something like: select * from table where field in
I would like do something like that. list_of_urls = ['http://www.google.fr/', 'http://www.google.fr/', 'http://www.google.cn/', 'http://www.google.com/', 'http://www.google.fr/',
I would like to do something like the following with spark. <viewdata model=IList[[string]] />
I would like to use something like the following: SELECT city FROM cities WHERE
I would like to do something like this i.e., use wild card characters in

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.