We help IT Professionals succeed at work.

Find Control problem in visual studio 2005

326 Views
Last Modified: 2013-11-26
I am changing our website over from using visual studio 2003 to 2005 so basically the code does not really need to change apart from some pathing issues.  I am having a problem with a findcontrol...I have a control call marketingcampain which is on a summary page.  When the user click on the placing order button the code is supposed to pick up the marketing control which consists of a dropdown list and a text box and simply pass the chosen info to the database.  
I try to access the marketing control in the code behin but the control has a value of nothing:

Dim tempMarketingCampaign As New General_MarketingCampaign
tempMarketingCampaign = Me.FindControl("MarketingCampaign1")
tempAdNamesList = tempMarketingCampaign.FindControl("AdNamesList")
tbAddInfo = tempMarketingCampaign.FindControl("tbOther")

I get an error that says object not set to instance of an object.  I am very confused as the code has not actually changed at all and in visual studio 2003 it worked fine.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Are you using master pages with 2.0?

Bob

Author

Commented:
I am using master pages with visual studio 2005...does that make a difference?

At the top of the summary page in the code behind it has:

Partial Class Basket_summary
    Inherits System.Web.UI.Page

At the top of the summary page html it has:

<%@ Page Language="VB" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="false" CodeFile="summary.aspx.vb" Inherits="Basket_summary" title="Untitled Page" %>
<%@ Register Src="../General/MarketingCampaign.ascx" TagName="MarketingCampaign"
    TagPrefix="uc1" %>

At the top of the marketing control in the code behind it has:

Partial Class General_MarketingCampaign
    Inherits System.Web.UI.UserControl


I have moving the control to the same folder that the summary control is in but it didnt make any difference.  I have tried changing partial class to public class and have taken out general in marketing campaign in the code behind and html but nothing seems to make any difference.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Do you know any links that will explain it or give examples?  I tried variation of Dim main As ContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder) and it doesnt work...
Thanks for you help on this.

Author

Commented:
Okay, I managed to get it to work as follows:

tempMarketingCampaign = Master.FindControl("ContentPlaceHolder1").FindControl("MarketingCampaign1")
 tempAdNamesList = tempMarketingCampaign.FindControl("AdNamesList")
 tbAddInfo = tempMarketingCampaign.FindControl("tbOther")

Thanks for comment :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.