CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 8/22/2007 5:49:52 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 6 Views: 52 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
7 Items, 1 Pages 1 |< << Go >> >|
enghsiang
Asp.Net User
FindControl in masterpage problem8/22/2007 5:49:52 AM

0/0

i place a hyperlink at my master page,and i wish to change the text of the hyperlink when user login into the system.

all my page are running at the content holder.

can someone show me the example for the code in vb.net? including the declaration and everything.

thanks


About me :
Language : VB.Net ---------->Newbie
Database : MySQL ----------->Newbie
Position : Web Programmer--->Newbie
--------------------------------------------------
Conclusion : A Totally Newbie....
deblendewim
Asp.Net User
Re: FindControl in masterpage problem8/22/2007 8:35:25 AM

0/0

 Hi enghsiang,

Do you mind that I use a LinkButton instead of an html hyperlink? This is easier to reference etc.

 

Ok, I have this on my masterpage:

 

<asp:LinkButton ID="LinkButton1" PostBackUrl="http://www.google.be" runat="server">LinkButton</asp:LinkButton>

 

Then, when a childpage loads, I will change the url of the linkButton:
The following happens in the load event of a childpage:

 

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	Dim dummy As LinkButton
	dummy = CType(Master.FindControl("LinkButton1"), LinkButton)
	dummy.PostBackUrl = "http://www.asp.net"
  End Sub

 
 If you have questions/remarks/comments, please do so!
Kind regards,
Wim
 


8 out of 10 questions are already answered! Google it!!
enghsiang
Asp.Net User
Re: FindControl in masterpage problem8/22/2007 8:51:00 AM

0/0

deblendewim:

 Hi enghsiang,

Do you mind that I use a LinkButton instead of an html hyperlink? This is easier to reference etc.

 

Ok, I have this on my masterpage:

 

<asp:LinkButton ID="LinkButton1" PostBackUrl="http://www.google.be" runat="server">LinkButton</asp:LinkButton>

 

Then, when a childpage loads, I will change the url of the linkButton:
The following happens in the load event of a childpage:

 

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	Dim dummy As LinkButton
	dummy = CType(Master.FindControl("LinkButton1"), LinkButton)
	dummy.PostBackUrl = "http://www.asp.net"
  End Sub


 If you have questions/remarks/comments, please do so!
Kind regards,
Wim
 

Wim,thanks for your reply

actually i also manage to change the hyperlink text already.but just i face another problem.

the problem is,as i hav lot of page in my system,once i redirect to other page ( which the page in content holder),the hyperlink at masterpage turn back to normal. any idea?


About me :
Language : VB.Net ---------->Newbie
Database : MySQL ----------->Newbie
Position : Web Programmer--->Newbie
--------------------------------------------------
Conclusion : A Totally Newbie....
deblendewim
Asp.Net User
Re: FindControl in masterpage problem8/22/2007 1:56:24 PM

0/0

Hi,

Hmm, let me try to understand what you are trying to accomplish .....

So, you have a HyperLink on the masterpage. A user logs in, and when this happens, the link should have a changed text depending on the user who logged in.

Am I right so far?

 

Well, the hyperlink's text will get lost on redirection because the text was changed at runtime. Hmmm, viewstate can persist it, but only on the same page I guess (I mean, when a postback occurs).
I would suggest the following (not sure if it's a best practice because I'm no masterpage guru).

  1. Your hyperlink is on the masterpage
  2. once a user log's in, create a sessionvariable to store the custom text in.
  3. in the Load of the masterpage, do the following
 
If Not Session("mySessionVariable") Is Nothing Then
  Me.hyperLink1.Text = "blabla" & Session("UserInformation") & "whatEverYouWantToCallIt"
End If
 

 So in words ....

When a user log's in, a sessionVariable is filled. Now, whenever you redirect between content pages, the load of the masterpage will be triggered. Then the code will do: Is there a sessionVariable? If yes, then my hyperlink must change.

Depending on how you wish to change the hyperlink's text you might not need a sessionVariable (which is always better!). For example: Do you want the hyperlinkText to be something like "Logout here" & UserName, then in the load of the masterpage you could do something like: Me.hyperLink1.Text = "Logout here" & User.Identity.Name.

 

Hope this helps!
Wim
 


8 out of 10 questions are already answered! Google it!!
enghsiang
Asp.Net User
Re: FindControl in masterpage problem8/23/2007 1:52:30 AM

0/0

deblendewim:

Hi,

Hmm, let me try to understand what you are trying to accomplish .....

So, you have a HyperLink on the masterpage. A user logs in, and when this happens, the link should have a changed text depending on the user who logged in.

Am I right so far?

 

Well, the hyperlink's text will get lost on redirection because the text was changed at runtime. Hmmm, viewstate can persist it, but only on the same page I guess (I mean, when a postback occurs).
I would suggest the following (not sure if it's a best practice because I'm no masterpage guru).

  1. Your hyperlink is on the masterpage
  2. once a user log's in, create a sessionvariable to store the custom text in.
  3. in the Load of the masterpage, do the following
 
If Not Session("mySessionVariable") Is Nothing Then
  Me.hyperLink1.Text = "blabla" & Session("UserInformation") & "whatEverYouWantToCallIt"
End If
 

 So in words ....

When a user log's in, a sessionVariable is filled. Now, whenever you redirect between content pages, the load of the masterpage will be triggered. Then the code will do: Is there a sessionVariable? If yes, then my hyperlink must change.

Depending on how you wish to change the hyperlink's text you might not need a sessionVariable (which is always better!). For example: Do you want the hyperlinkText to be something like "Logout here" & UserName, then in the load of the masterpage you could do something like: Me.hyperLink1.Text = "Logout here" & User.Identity.Name.

 

Hope this helps!
Wim
 

Actually what i wan is something like a mail box system:

1. the system will detect the database whether there are any new mail,then it will change the hyperlink text to maybe like : " 2 New Mail or 0 New Mail ".    and it will link the user to inbox when user click on it.

2. the hyperlink will only be visible when the user login into the system. i accomplish this by the example u giv to me,just some modification on it. thanks for the example.

so now,any idea on 1. ? where should i locate my code to check the database and change the hyperlink text?

hope to get your reply soon and thanks very much for your help.Big Smile


About me :
Language : VB.Net ---------->Newbie
Database : MySQL ----------->Newbie
Position : Web Programmer--->Newbie
--------------------------------------------------
Conclusion : A Totally Newbie....
deblendewim
Asp.Net User
Re: FindControl in masterpage problem8/23/2007 11:09:48 AM

0/0

enghsiang:
1. the system will detect the database whether there are any new mail,then it will change the hyperlink text to maybe like : " 2 New Mail or 0 New Mail ".    and it will link the user to inbox when user click on it.

Hey,

Hmm, that's indeed another problem.

Well, I can't give you an exact answer, but I'll try to give you some possible solutions ...

First you need to know how frequently you want the value to be updated. Do you want it to be real-time, or with intervals of 5 minutes?

 

I should set up a webservice. That webservice checkes for example the amount of mails for a specific user. So, you give the userName as parameter, (example: Bob) and the service returns the amount of mails (example: 3). Then you add a timer to your masterpage. Every time the timer ticks, you call the webservice, and update the Text-property of the HyperLink.

With this setup you can also call the service on other times. For instance when the user log's in, or when he presses Send/Recieve (or something like that) in the mailBox-system.

 

That's a way to go .... although I'm not sure it's very performant.

Maybe you should open a new thread with the specific question of how to "Detect database changes & update values on that".

Because I think a dataset is also capable of detecting database changes. Let's say you have a datatable where you inserted the emailAmount values. Then you could perform a check to see if the data is dirty (=changed). That could also be a condition to update the Text of the HyperLink.  But I'm not quite sure how to implement that into your solution. Maybe other know howto, or they can point you in the right direction.

 

Kind regards,
Wim


8 out of 10 questions are already answered! Google it!!
enghsiang
Asp.Net User
Re: FindControl in masterpage problem8/24/2007 1:58:45 AM

0/0

Wim, 

your suggestion is good. but i'm trying to reduce to loading process in my system.so currently i not considering the timer method. anyway,still thanks for your idea as it may be an extra option for me.

and also,i already open a new thread regarding the problem.

thanks Smile


About me :
Language : VB.Net ---------->Newbie
Database : MySQL ----------->Newbie
Position : Web Programmer--->Newbie
--------------------------------------------------
Conclusion : A Totally Newbie....
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
ASP.NET 2.0: A Developer's Notebook Authors: Wei Meng Lee, Pages: 326, Published: 2005
ASP.NET 2.0 Cookbook Authors: Michael A. Kittel, Geoffrey T. Leblond, Pages: 989, Published: 2005
Professional C# 2005 with .NET 3.0 Authors: Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner, Pages: 1748, Published: 2007
Visual C# 2005: A Developer's Notebook Authors: Jesse Liberty, Pages: 221, Published: 2005
ASP.NET 2.0 MVP Hacks and Tips Authors: David Yack, Joe Mayo, Scott Hanselman, Fredrik Normén, Dan Wahlin, J. Ambrose Little, Jonathan Goodyear, Pages: 400, Published: 2006
Professional C# 2008 Authors: Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner, Pages: 1782, Published: 2008
Gui Autorizado Microsoft Visual Basic 2005 Authors: Lorenzo Ridolfi, Pages: 0, Published: -1

Web:
Problem Findcontrol and Masterpage - ASP.NET Forums Re: Problem Findcontrol and Masterpage. 07-02-2006, 12:59 PM. Contact ... Re: Problem Findcontrol and Masterpage. 07-02-2006, 9:54 PM ...
FindControl() doesn't work if page has MasterPage - ASP.NET Forums This is the problem: the method returns a NullReferenceException if I call it from a page that has a MasterPage because FindControl is not ...
ASP.NET 2.0 MasterPages and FindControl() - Rick Strahl's Web Log The problem is that when you use MasterPages the page hierarchy drastically changes. Where a simple this.FindControl() used to give you a control instance ...
How to: Reference ASP.NET Master Page Content The following code example shows how to use the FindControl method to get a reference to two controls on the master page, a TextBox control and a Label ...
C# Orcas: Master Page & Find Control Master Page & Find Control. this.FindControl("myControl"); ... I'm having a similar problem in that my user control is unable to reference the page it's on. ...
NET Questions - nested masterpages problem.. and I have a page that uses the nested masterpage. Problem I have is that in the Page_Load of the page I can't seem to do a FindControl that ...
upload findcontrol in masterpage - telerik Forum As for the Master page set up I have a masterpage with one contentplaceholder ... FindControl("txtRole") as TextBox; My problem now is that I can't get the ...
can't find control in master page Old 06-02-2006, 10:59 AM. Default can't find control in master page. Hi, In my master page I have :
...
Using FindControl with a MasterPage in ASP.NET & C# For example, if we have a label within a MasterPage, and we want to reference this label from a Content Page, then we would have to use the FindControl ...
Dynamically adding Content blocks to Masterpage fails after Master ... The problem I am having is that in the above example when I call one of the commented Master.FindControl lines, the TextBox no longer renders. ...




Search This Site:










custom module example

mixed mode authentication = no module controls ?!?!?

using dnn

how to insert seperator in solpart menu?

belfast dotnetnuke meeting

solpartmenu compatibility

odd error - can't view any .ascx files in vs 2003

we're taking applications...

3.0.11 issues/enhancement: module definitions

can't see admin pages after 2.0.3 new install

solpart menu: displaying sub nav as the root nav.

how can i change width of left pane?

minimum ntfs security rights for dnn 2.1.2

how to change data providers?

older version of dnn

need clue to debug 2.0 pa

dnn module for 3 - play mpeg in page

search problems when upgrading to v4

giving certain roles access to admin pages

i'have a problem to debug dotnetnuke

is roles working 3.0.7?

parent and child portal trouble

need a module for workflow management.

administration limitation.

dnn b3 -> final release windows 2003server permissions prob.

treeview control parent link missing

hidden modules

uploading of skins in dnn

dotnetnuke.....xxl ...ml ?

dnn modules

  Privacy | Contact Us
All Times Are GMT