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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:32:40+00:00 2026-05-27T13:32:40+00:00

hi guys i have a weird prob here.. i have this dropdownlist where different

  • 0

hi guys i have a weird prob here..
i have this dropdownlist where different values will hide/show some of the textbox in the page

 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
              <asp:ListItem>Multiple Choice Question</asp:ListItem>
              <asp:ListItem>Free text answer</asp:ListItem>
                            </asp:DropDownList>

C# code behind, inside Page_Load:

   if (Page.IsPostBack)
    {
        if (DropDownList1.SelectedValue == "Multiple Choice Question")
        {
            tb_ans.Visible = true;
            tb_ans2.Visible = true;
        }
        else
        {
            tb_ans2.Visible = false;
            tb_ans.Visible = false;
        }
    }
    if (!Page.IsPostBack) //the code within this statement will only load
    {
        Session["no"] = null;
        this.opt3.Attributes["style"] = "display: none;";
        .....
        opt3.Visible = false;
        ....
    }

Tried to debug and the result was : (i set breakpoint in page load)
when i select different value from the dropdownlist.
3rd time on changing the value, it looks like the dropdownlist keep the same value as the 2nd value.

the loop always go to the if(ddl.selectedvalue==”multiple…”)
. As a result, it will not hide the textbox that i want if the value is change to “free text…”

example :

  1. default selection ‘multiple choice..’

  2. change to ‘free ans..’ will hide the textbox but other button is not firing.

  3. change back to ‘multiple choice…’ it will turn back to ‘free ans..’

  4. ddl.selected value is still multiple choice.

what is the problem here..

  • 1 1 Answer
  • 1 View
  • 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-27T13:32:41+00:00Added an answer on May 27, 2026 at 1:32 pm

    Because of this: if (!Page.IsPostBack)

    Remove that.

    That means it only works for the first time of the page load.

    If you remove that, that function will run for every page load.

    But why don’t you use the dropdownlist selected index change event??

    That’s better.

    Don’t forget to add AutoPostBack="true" in your aspx dropdownlist

    Ok. I want to write like this.

    in aspx

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Selected="True" Value="multiple">Multiple Choice Question</asp:ListItem>
            <asp:ListItem Value="free">Free text answer</asp:ListItem>
    </asp:DropDownList>
    

    in cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.PostBack)
        {//write your other things which are not related to DropDownList1  }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(DropDownList1.SelectedValue.ToString().Trim().Contains("multiple"))
        {
            ////do something
        }
        else if (DropDownList1.SelectedValue.ToString().Trim().Contains("free"))
        {
            //do something
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I have a weird error I wrote this code against setbubblepopup $(document).ready(function
Hi guys I have a weird question, I have a cli php script runs
Hey guys, I have a weird problem. I have an update system that refreshes
Thus far you guys have been wildly helpful with me getting this little ditty
guys i have arrays in which i have to match this kind of text
Guys i have a WebView in my Screen with some TextFields in it. Whenever
Hey guys I got a weird issue.. I have a datalist that's only loaded
I have this weird issue that jquery.load sometimes fails on chrome. I'm not gonna
Hey guys I'm getting a syntax error on my CONCATS for some reason, this
OK guys, I have a weird problem, I have been using set_include_path before eaccelerator

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.