Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about programmatically setting visibility on asp:hyperlink

Status
Not open for further replies.

zerkat

Programmer
Jul 12, 2007
103
US
Hi,

I have a series of links that I want to be visible only when the url is equal to a certain address. I am using the asp:hyperlink control with unique ids. In my code behind I have:

Inherits System.Web.UI.UserControl

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

Dim serverURL As string
If serverURL = " Then
hyperlinkID.Visible = False
Else
hyperlinkID.Visible = True
End IF
End Sub

My question is that this code worked once but now I am receiving an error that my hyperlinkID needs to be declared. Since it is an id of a control how would I declare it, or is there something else wrong? Also how would I incorporate using the Request.Url.ToString to get the url of the page a person is on dynamically? I do not want to hard code it.

Since request is not part of the System.Web.UI.UserControl I receive an error. I have looked at several tutorials for .net and understand them but when I go to write code I am completely lost and overwhelmed...please help.
 
ok - nevermind. a coworker looked over it and pointed out my silly mistakes....

in case any other newbie for .net is having a similar problem:

Dim serverURL
ServerURL= Request.URL.ToString
IF serverURL = " them
hyperlinkID.Visible = False
Else
hyperlinkID.Visible = True
End if
 
is there a way in asp.net to tell is a url contains a certain word?

instead of checking on the whole url it would probably be better if i could just check to see if the website address has one word in it. would I have to get the whole url and parse it or is there an easier method?
 
First make sure your variables have a type when you delcare them
Code:
Dim serverURL [red] as String[/red]

Then do something like
 if serverURL.contains("the string  you are lookng for") then
....
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top