CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 12/28/2006 10:46:47 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 7 Views: 35 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
8 Items, 1 Pages 1 |< << Go >> >|
lcountee
Asp.Net User
programatically referencing a control in a master page12/28/2006 10:46:47 PM

0/0

I want to programatically access a HyperLink control within a master page in order to change the control's NavigateUrl value. The following code is in the master page:

HyperLink PrintLink = (HyperLink)Master.FindControl("PrintLink");

 gets me a NullReferenceException. The control exists; here is the code for the control (also in the master page):

<

asp:HyperLink ID="PrintLink" runat="server" CssClass="navigation" NavigateUrl="#">Print</asp:HyperLink>
 Why can't it see the control?
Rossoneri
Asp.Net User
Re: programatically referencing a control in a master page12/29/2006 4:48:46 AM

0/0

If you are working in the code beside of the master page, then you should be able to just access the control directly. No need to use FindControl()

PrintLink.NavigateUrl = "/";
moredotnet
Asp.Net User
Re: programatically referencing a control in a master page12/29/2006 6:40:57 AM

0/0

Try this... 

Protected

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

hl1.NavigateUrl =

"http://www.hotmail.com"

End Sub

where....

<

asp:HyperLink ID="hl1" runat="server" Text="CLICK HERE" NavigateUrl="http://www.yahoo.com"></asp:HyperLink>

 

See that the hyperlink's navigate URL property can be changed at runtime. You use any event as you want (I've used the Page_Load) .

Also, if you are using an ASP.NET Ajax application, then you would need to add this in your web.config...

<

pages >

<

namespaces>

<

clear/>

<

add namespace="System"/>

<

add namespace="System.Collections"/>

<

add namespace="System.Collections.Specialized"/>

<

add namespace="System.Configuration"/>

<

add namespace="System.Text"/>

<

add namespace="System.Text.RegularExpressions"/>

<

add namespace="System.Web"/>

<

add namespace="System.Web.Caching"/>

<

add namespace="System.Web.SessionState"/>

<

add namespace="System.Web.Security"/>

<

add namespace="System.Web.Profile"/>

<

add namespace="System.Web.UI"/>

<

add namespace="System.Web.UI.WebControls"/>

<

add namespace="System.Web.UI.WebControls.WebParts"/>

<

add namespace="System.Web.UI.HtmlControls"/>

</

namespaces>

</

pages>

 Cheers!

moredotnet

 


Cheers
Vishal Khanna | MCAD.NET | Intersoft Data Labs
(Please mark as answer if reply helps)


.NET Interviews & FAQs @ www.dotnetUncle.com



Search & Post Free Ads

lcountee
Asp.Net User
Re: programatically referencing a control in a master page12/29/2006 1:49:28 PM

0/0

Thanks for the responses.

Rossoneri - I actually tried what you have before I posted to this forum. That gets me an error that says "The name 'PrintLink' does not exist in the current context."

moredotnet - From my limited understanding of VB, it looks like you did the same thing that I did in C# - my event is actually in the page's onLoad event also. I'm not using AJAX for this app.

Other suggestions?

lcountee
Asp.Net User
Re: programatically referencing a control in a master page12/29/2006 2:02:36 PM

0/0

I tried this again on a different master page, and it worked - not sure what happened with this one, but I'm going to delete the control and insert a new one. Thanks again for the suggestions.
moredotnet
Asp.Net User
Re: programatically referencing a control in a master page1/2/2007 1:12:12 PM

0/0

Please mark the appropriate post as the answer!

Even I didnt use Ajax. I'm sure the same code will work in C# too after conversion.

Cheers!

moredotnet 

 


Cheers
Vishal Khanna | MCAD.NET | Intersoft Data Labs
(Please mark as answer if reply helps)


.NET Interviews & FAQs @ www.dotnetUncle.com



Search & Post Free Ads

lcountee
Asp.Net User
Re: programatically referencing a control in a master page1/2/2007 1:32:56 PM

0/0

moredotnet - I did mark the appropriate post as the answer. Your reply did not help me to resolve the issue.
moredotnet
Asp.Net User
Re: programatically referencing a control in a master page1/3/2007 5:35:56 AM

0/0

Hmmmmmm!Surprise
Cheers
Vishal Khanna | MCAD.NET | Intersoft Data Labs
(Please mark as answer if reply helps)


.NET Interviews & FAQs @ www.dotnetUncle.com



Search & Post Free Ads

8 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Programming Microsoft ASP.NET Authors: Dino Esposito, Pages: 1165, Published: 2003
CHI 2006: Interact, Inform, Inspire : Conference Proceedings : Conference on Human Factors in Computing Systems : Montreal, Quebec, Canada, April 22-27 Authors: Rebecca Grinter, Pages: 2, Published: 2006
Pro C# 2008 and the .NET 3.5 Platform Authors: Andrew Troelsen, Pages: 1370, Published: 2007
Programming Microsoft Visual Basic 6.0: [master Object-oriented Programming Techniques for Rapid 32-bit Development] Authors: Francesco Balena, Pages: 1276, Published: 1999

Web:
How to: Reference ASP.NET Master Page Content Gets a reference to a Label control that not in // a ContentPlaceHolder Label mpLabel = (Label) ... Working with ASP.NET Master Pages Programmatically ...
Programatically including a JavaScript reference into a master ... Programatically including a JavaScript reference into a master page from another control. Last post 08-24-2008 7:37 AM by lunchtimemama. ...
The Official Microsoft ASP.NET Site Looks at setting the content page’s master page programmatically via the PreInit ... Step 1 in Figure 1 shows the initial content and master page control ...
Master Pages :: Specifying the Master Page Programmatically ... Figure 01: The Master Page and Content Page's Control Hierarchies are Fused ..... Rather than referencing a file path, the @MasterType property now ...
Scott on Writing Jun 11, 2008 ... Control ID Naming in Content Pages [VB | C#] - both master pages and ... It also complicates programmatically referencing the controls in ...
How to refer Master page content in Content Page - Vikram Lakhotia Feb 26, 2008 ... For controls we can refer any control on the master page independent of referencing public member. We can use the @MasterPage directive in ...
Events in Master and Content Pages For controls, events are handled locally—a control in a content page raises ... Working with Master Pages Programmatically Referencing Master Page Content ...
Master Pages 101: Using VB 2005 to Access Master Page ASP.NET ... The Master object provides a programatic reference to the Master Page from a content ... With this property in place on the master page, referencing the ...
ASP.NET.4GuysFromRolla.com: Passing Information Between Content ... Jan 31, 2007 ... Here DataFromPage is a Label Web control in the Master Page's ... the Master Page's public methods and properties programmatically in the ...
Master Pages in ASP.NET 2.0 This tutorial on master pages is for beginners, hings can get more complicated with master pages, such as programmatically including master pages in your ...




Search This Site:










page inheritance and usercontrols issues

menuitem separator

single dataprovider for multiple pas...

speed issues and code analysis

dnn and web service response

masterpage with treeview sitemap and contentpanel

i am stuck trying to edit [sidemenu]

checking indexed items properties

server control registering client script

how to let in webbrowser

visual studio 2005 complaints

url rewriting blog entries

datasets in asp.net 2.0

how do i deploy???

bug 3.0.11 urlrewrite cause exception

dynamically show flash animation

imports excel : namespace not found

is there a limit?

create a forum in vwd

adding tier

menu link module

.net 1.1 to 2.0 "remember me" checkbox no longer works

display session key in global function/subroutine

does any guy use the feature "submit the page to google"

login error after site move

why has asp.net appeared as an account holder on my computer?

very, very basic question

evolution of visual studio

how do i access a control from a different vb.net code module?

vs2005 help favorites

 
All Times Are GMT