Solved

findControl

Posted on 2006-07-11
4
678 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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