Solved

findControl

Posted on 2006-07-11
4
683 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

751 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