Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on an asp.net/C# project and I am a beginner in webprogramming. I get the below error on runtime:

"Object reference not set to an instance of an object."

Below is my code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            txtUsername.Focus();
            if (cmbThemes.SelectedItem.Text=="Red")
            {
                pnlSignin.Border.BorderColor = Color.Orange;
            }
        }


cmbThemes is a combobox.

Thanks in advance
Posted
Updated 26-Nov-13 20:26pm
v2
Comments
Karthik_Mahalingam 27-Nov-13 1:57am    
how combobox came in asp ???
pls modify your question....
Rahul Krishnan R 27-Nov-13 2:24am    
I am using DevExpress web controls.It has combobox.
Karthik_Mahalingam 27-Nov-13 2:52am    
Sorry dude, but always pls mention in detail :)
Maciej Los 27-Nov-13 1:58am    
My guess: SelectedItem doesn't exists in this context, because you have moved focus to the other control.
Thomas ktg 27-Nov-13 2:01am    
Make sure the ComboBox is bound with the datasource and that has value in it before checking with if statement.

Either your dropdown does not contain the Item named as Red or the dropdown does not contain any items.
Please check all the Items in the dropdown.
 
Share this answer
 
Comments
Rahul Krishnan R 27-Nov-13 2:28am    
I am getting the error inside the if condition. pnlSignin is the panel i am using and getting the error there.
[no name] 27-Nov-13 2:53am    
can you post your .aspx and .aspx.cs code here, i will try to solve your problem..
You are getting this error because you are trying to access the selecteditem.text property in the page load without binding the dropdown!!!!!
 
Share this answer
 
Comments
Rahul Krishnan R 27-Nov-13 2:28am    
I am getting the error inside the if condition. pnlSignin is the panel i am using and getting the error there.
JoCodes 27-Nov-13 3:08am    
Yes .. Madhu is right .. Your combobox is not loaded/bound yet..Debug and check
Hi,

Put debug point at that line.

Now check pnlSignin is null or its an instance.

If its null then check your aspx page or send the whole code to us
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900