Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 46172 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > object reference not set. ...
Gayathri

object reference not set.

Replies: 3 | Posted by: Gayathri on 4/8/2010 | Category: ASP.NET Forums | Views: 1373 | Status: [Member]  


protected void chkInTheatres_CheckedChanged1(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)FindControl("chkInTheatres");
if (cb.Checked == true) ---> raises error here "Object reference not set"
{
Response.Write("InTheatres");
}
else
{
Response.End();

}

}

even if i check (if cb != null) simply says it is null for everything.

please help.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Raja
Raja  
Posted on: 4/8/2010 10:14:17 PM
Level: Starter | Status: [Member]

Looks like following code is not working

CheckBox cb = (CheckBox)FindControl("chkInTheatres"); 


I think you should write in following ways

CheckBox cb = (CheckBox)this.Page.FindControl("chkInTheatres");


Have you kept this code into user control or page? if in user control then use this.FindControl if page then this.Page.FindControl if in master page then this.page.Master.FindControl



Regards,
Raja, USA

Gayathri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Pavanandey
Pavanandey  
Posted on: 4/9/2010 1:23:43 AM
Level: Bronze | Status: [Member]



the event which ur using is directly refering to the check box so u need not go for findcontrol method u can directly use this

<asp:CheckBox ID="CB1" runat="server" oncheckedchanged="CB1_CheckedChanged" />

protected void CB1_CheckedChanged(object sender, EventArgs e)
{
bool status = CB1.Checked;
}

Thanks
Pavan Kumar
Mark Answer if this fits the need

Gayathri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sabarees
Sabarees  
Posted on: 4/15/2010 1:19:26 PM
Level: Starter | Status: [Member]

Hi Gayathri,

Use the below code into your CheckedChanged event,

protected void chkInTheatres_CheckedChanged1(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;

if (cb.Checked == true)
{
Response.Write("InTheatres");
}
else
{
Response.End();
}
}

Best Ragards,
Sabarees M

Gayathri, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 9:47:11 AM