Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 29th, 2009, 12:56 PM
Authorized User
Join Date: Oct 2007
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in child page with Hyperlink.Attributes.Add

Hello All,

I am having a weird problem Hyerlink.Attribute.Add("onclick"). The code i am using is as foolwing -

HyperLink h1 =(HyperLink)Form.FindControl("hlnkPatienType");
h1.Attributes.Add("onclick", "window.open('TypePatient.aspx',null,'left=700 , top=50, height=600, width= 500, status=n o, resizable= no, scrollbars= no, toolbar= no,location= no, menubar= no');");

I am writing this code in Page_Load event.This code works perfectly fine when used in a simple form. But as soon as i added a master page and had written this code in child page it is showing me "Object Reference not set to an instance of an object." error. Can someone please help me to fix it. Thanks in Advance.
Old October 30th, 2009, 08:47 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

The reason for this behavior is that with a master page the naming container has changed. You now need to search in a different naming container: the ContentPlaceHolder in the master page. This should work:

HyperLink h1 =(HyperLink)Master.FindControl("ContentPlaceHolder 1").FindControl("hlnkPatienType");

For more details, take a look here: http://west-wind.com/weblog/posts/5127.aspx


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in child page with Hyperlink.Attributes.Add nrlahoti ASP.NET 2.0 Professional 1 October 30th, 2009 10:12 AM
this.attributes.add not working millerthegorilla SharePoint Development 1 June 17th, 2008 03:44 AM
simple wish: to add 'http://' to a HyperLink bananas ASP.NET 2.0 Basics 1 June 21st, 2006 08:41 AM
Calling Javascript Function With Attributes.Add OutCaster ASP.NET 1.0 and 1.1 Basics 1 January 27th, 2006 09:53 PM
Child Page Problem with Handles My.Base Load bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 1 October 4th, 2004 09:30 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.