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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:28:06+00:00 2026-05-26T14:28:06+00:00

I have two problems that I’m not sure are related: I have two DropDownList

  • 0

I have two problems that I’m not sure are related:

I have two DropDownList controls (initially set to not visible) and a RadioButtonList control with autopostback behaviour set to true.

Whenever Postback occurs, I want to read the SelectedValue property from the RadioButtonList control – and depending on that, make one of the DropDownLists visible.

Here’s my problem:

1) I can’t directly refer to the RadioButtonList control by its ID. The designer.cs file doesn’t seem to generate either the RadioButtonList or DropDownList controls. Even if I manually add the controls to the designer.cs file, they are lost upon regenerating. Is this expected behaviour?

2) I tried using the Page.FindControl property in the Page_Load() method.

if(Page.PostBack==true)
{
    RadioButtonList rbl = (RadioButtonList)Page.FindControl("RadioButtonList1");
    if(rbl.SelectedValue=="optionA")
    {
         DropDownList ddA = (DropDownList)Page.FindControl("DropDownListA");
         ddA.Visible = true;   
    }
    else
    {
         DropDownList ddB = (DropDownList)Page.FindControl("DropDownListB");
         ddB.Visible=true;
    }
}

But I’m getting a NullReferenceException at the if condition.

Am I completely on the wrong track? Will someone guide me about the best way to achieve what I want to do?

Also, what can I do to make designer.cs file load the Controls?


EDIT: /facepalm

I figured it out myself. I’d forgotten than I’m using the control inside a table.

Once I moved the Control outside the Table, I could refer to the ID directly.

A lack of sleep and coffee to blame. My apologies. Thank you for the 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-26T14:28:07+00:00Added an answer on May 26, 2026 at 2:28 pm

    Page.FindControl is not recursive, i.e it’ll return null if the dropdownlist1 controls is in some other control.
    check this link for detail and see will you be able to find the dropdownlist correctly.

    http://www.mha.dk/post/Recursive-PageFindControl.aspx

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

Sidebar

Related Questions

I have two problems which are related. 1) I have a batch file that
I have two related problems that occur in the following situation. I have a
I have my program that can draw rectangles. I have two problems I can't
I have some localization problems in my webpage. There are basically two problems (that
I have two cmake-related problems: first, I can't make it to find the includes
I'm quite a beginner at database design. I have two problems that I'd like
I have two problems. The first one is that I'm using JSP and that
I know, I know, now I have two problems 'n all that, but regex
I have two problems with the below code that I need help fixing: 1)
I am using DllImport in my solution. My problem is that I have two

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.