Solved

findControl

Posted on 2006-07-11
4
672 Views
Last Modified: 2008-02-01
Hello,

I am trying to do the following in my page load event of the events calendar that comes with the clubsite starter kit;-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/clubwebsitesk.asp

 protected void loadPage(object sender, EventArgs e)
    {
        eventscalendar.DataSource = FixedAuctions.AuctionsDB.ShowSalesCalendar(AuctionSiteID, VendorID, VehicleTypeID, AuctionTypeID);
        eventscalendar.DataBind();

        HyperLink HyperLink1 = (HyperLink)eventscalendar.FindControl("HyperLink1");
        HyperLink1.Attributes.Add("onclick", "window.open('popup.aspx',null,'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');");
    }

But I get the following error;-
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 36:
Line 37:         HyperLink HyperLink1 = (HyperLink)eventscalendar.FindControl("HyperLink1");
Line 38:         HyperLink1.Attributes.Add("onclick", "window.open('popup.aspx',null,'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');");
Line 39:     }
Line 40:
 

Source File: c:\Inetpub\Www_root\pma\stock_locator\sales_calendar.aspx.cs    Line: 38


How do I go about finding controls in this case.
0
Comment
Question by:claracruz
4 Comments
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 17088129
Hi claracruz,

your syntax is proper but are you sure you have put HyperLink1(case sensitive name string in findcontrol) control in event calendar ?


Regards,
NetSwap
0
 
LVL 15

Expert Comment

by:deepaknet
ID: 17088185
Also, did you miss the runat="server" attribute? In that case, CodeBehind will not be able to find your control.
0
 
LVL 3

Accepted Solution

by:
harshits earned 500 total points
ID: 17088574
Hi,

Is the hyperlink control inside a template column within the eventscalendar? If it is so then the above syntax won’t work. For a template column this is how it should be

 HyperLink HyperLink1 = (HyperLink)eventscalendar.Items[0].FindControl("HyperLink1");

Try the above code. Also if possible please give the html code of the control in the aspx. This will help in identifying how the control is formed and accordingly write the code to retrieve the control within it.

Harshit Sheth
0
 
LVL 4

Author Comment

by:claracruz
ID: 17098441
I tried to d the ites[0] thingy, but I get error Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'ControlSample.EventCalendar' does not contain a definition for 'Items'

Source Error:

 

Line 35:         eventscalendar.DataBind();
Line 36:
Line 37:         for (int i = 0; i < eventscalendar.Items.Count; i++)
Line 38:         {
Line 39:             //HyperLink HyperLink1 = (HyperLink)eventscalendar.FindControl("HyperLink1");
 
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now