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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:20:09+00:00 2026-06-17T23:20:09+00:00

On page load the default value of the dropdownlist tell the user to select

  • 0

On page load the default value of the dropdownlist tell the user to select posible values.
Which is either Male or Female.If user did not select either of these values:Male or Female, the Genereate PatientNumber button should be disabled.
Otherwise the patient gender is generated base on the values select.
Currently if the dropdown is at default value i still can generate patientNumber.
Some one help me the cause of the error.i prefer the correct code.

protected void patient_num_Click(object sender, EventArgs e)
    {
        String gender = drl_gender.Text.ToString();
        string patientNumber = " ";
        RegistrationNumber Register_patient = new RegistrationNumber();
        patient_num.Enabled = false;
        if (gender=="Select Gender")
        {
            patient_num.Enabled = false;


        }
        else if (gender=="Male")
        {
            patient_num.Enabled = true;
            patientNumber = Register_patient.GeneratePatientNumber(Gender.Male).ToString();
            patientNumber = patientNumber.Replace("/", "-");
            txtpatientNum.Text = patientNumber;


        }
        else
        {
            patient_num.Enabled = true;
            patientNumber = Register_patient.GeneratePatientNumber(Gender.Female).ToString();
            patientNumber = patientNumber.Replace("/", "-");
            txtpatientNum.Text = patientNumber;

        }


    }
  • 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-06-17T23:20:10+00:00Added an answer on June 17, 2026 at 11:20 pm

    The problem in your code is that you are using the Text property of the DropDownList to determine what the user has selected(use SelectedValue instead). The Text property returns the text of the currently selected item but "" if no item is selected:

    MSDN:

    The Text property gets and sets the same value that the SelectedValuee
    property does. The SelectedValue property is commonly used to
    determine the value of the selected item in the ListControl control.
    If no item is selected, an empty string (“”) is returned.

    Now have a look at your code(remember String.Empty when nothing is selected):

    if (gender=="Select Gender")
    {
        patient_num.Enabled = false;
    }
    ....
    else
    {
        patient_num.Enabled = true;
        // here we are!
        patientNumber = Register_patient.GeneratePatientNumber(Gender.Female).ToString();
        patientNumber = patientNumber.Replace("/", "-");
        txtpatientNum.Text = patientNumber;
    }
    

    The solution:

    Use a RequiredFieldValidator instead to ensure that the user has selected a gender. You can use the InitialValue property to tell it the value for your "-- please select --" item.

       <asp:DropDownList id="DdlGender" runat="server" >
            <asp:ListItem Text="-- please select --" Value="-1"></asp:ListItem>
            <asp:ListItem Text="female" Value="1"></asp:ListItem>
            <asp:ListItem Text="male" Value="2"></asp:ListItem>
        </asp:DropDownList>
    
      <asp:RequiredFieldValidator id="RequiredGender" 
           InitialValue="-1" 
           ControlToValidate="DdlGender"
           ErrorMessage="Please select gender!"
           runat="server"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The default.aspx page has a DropDownList which is populated in the code behind only
Javascript has textObject.defaultValue=somevalue for retrieving the default value (stored value from page load) of
I am trying to get a default query to implement upon page load but
When I select a value in the dropdownlist I get a postback and the
GOAL: To load href value whenever somebody select option from the dropdown list -
I get the wrong value from my Dropdownlist (ddlCity). I always get the default
I have a DropDownList connected to an ObjectDataSource. In my page load i set
On page load I'm bootstrapping my data to my collections via this technique .
Is Page.Load the earliest point in the Page.Load life cycle to add Response.AppendHeader?
Q1) On page load is it possible with Jquery to check the file name

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.