Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

findControl

Posted on 2006-07-11
4
Medium Priority
?
692 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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