Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: How can you dynamically set the properties of a web server control?


Message #1 by "Jon Maz" <jonmaz@s...> on Wed, 13 Feb 2002 10:59:02
Hi,



I am trying to set one of the properties of a web server control 

dynamically, and don't know how it should best be done.



Specifically, I want to dynamically set the NavigateURL property of this 

Hyperlink control:



<asp:HyperLink runat="server" id="hlDisplayItemText" 

NavigateUrl="DisplayItemText.aspx" Text="Display ItemText" 

Target="_self" /> 



Firstly, this link should not always take the user to page 

DisplayItemText.aspx - I want to be able to link to other pages, depending 

on what else is going on on the page.



Secondly, I also want to pass variables from the current page to the 

linked page (whether this linked page is DisplayItemText.aspx or some 

other one), and was trying to do this via the query string.  However, my 

first naive attempt (below) just threw errors:



Dim strPassVariable as String = "?Variable=xyz"



<asp:HyperLink runat="server" id="hlDisplayItemText" NavigateUrl=<% 

Response.Write("DisplayItemText.aspx" & strPassVariable) %> Text="Display 

ItemText" Target="_self" /> 



I suspect I am still thinking ASP 3.0 - there must be some super, slick 

ASP.NET way of doing this!  Can anyone tell me how?



Thanks,



JON
Message #2 by Elissa Setarehshenas <elissasetareh@y...> on Wed, 13 Feb 2002 06:36:32 -0800 (PST)
Dear Jon,

You can set the hyperlink address inside one of your

functions like this



hlDisplayItemText.NavigateUrl = "theUrlofpageIwant";

when you do it that way don't put the NavigateUrl

attribute when describing the Hyperlink.



As far as passing variables from one page to another

use cookies.



Hope this helps.



Elissa



--- Jon Maz <jonmaz@s...> wrote:

> Hi,

> 

> I am trying to set one of the properties of a web

> server control 

> dynamically, and don't know how it should best be

> done.

> 

> Specifically, I want to dynamically set the

> NavigateURL property of this 

> Hyperlink control:

> 

> <asp:HyperLink runat="server" id="hlDisplayItemText"

> 

> NavigateUrl="DisplayItemText.aspx" Text="Display

> ItemText" 

> Target="_self" /> 

> 

> Firstly, this link should not always take the user

> to page 

> DisplayItemText.aspx - I want to be able to link to

> other pages, depending 

> on what else is going on on the page.

> 

> Secondly, I also want to pass variables from the

> current page to the 

> linked page (whether this linked page is

> DisplayItemText.aspx or some 

> other one), and was trying to do this via the query

> string.  However, my 

> first naive attempt (below) just threw errors:

> 

> Dim strPassVariable as String = "?Variable=xyz"

> 

> <asp:HyperLink runat="server" id="hlDisplayItemText"

> NavigateUrl=<% 

> Response.Write("DisplayItemText.aspx" &

> strPassVariable) %> Text="Display 

> ItemText" Target="_self" /> 

> 

> I suspect I am still thinking ASP 3.0 - there must

> be some super, slick 

> ASP.NET way of doing this!  Can anyone tell me how?

> 

> Thanks,

> 

> JON





$subst('Email.Unsub').





__________________________________________________

Do You Yahoo!?

Send FREE Valentine eCards with Yahoo! Greetings!

http://greetings.yahoo.com

Message #3 by "Jon Maz" <jonmaz@s...> on Thu, 14 Feb 2002 11:10:26
Hi,



Thanks for your great advice.  I have got it working now, actually doing 

the whole control dynamically in the end.  This is the current state of 

the code:



JON



*********************************************************



objHlDisplayItemText = new HyperLink

objHlDisplayItemText.ID = "hlDisplayItemText"

objHlDisplayItemText.NavigateUrl = "DisplayItemText.aspx?iCurrentRecord=" 

& ViewState("iCurrentRecord")

objHlDisplayItemText.Text="Display ItemText"

objHlDisplayItemText.Target="_self"

Page.FindControl("PlaceHolder1").Controls.Add(objHlDisplayItemText)	

	

*********************************************************

  Return to Index