Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
  #2 (permalink)  
Old October 30th, 2009, 08:47 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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!

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 05:33 AM.

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