Solved

findControl

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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