finding an HTML tag using ASP.NET

  • Thread starter Thread starter VR
  • Start date Start date
V

VR

Hi.

I have an ASP.NET web page, with a logo written in plain
HTML. One of the tags is an image that should read
either "sign on" or "sign off" depending on whether a user
has been authenticated:

<a href="javascript:void(FollowLink('SignOn'));">
<IMG src="/graphics/TopSignOn.gif" name="TopSignOn">
</a>

I'd like to determine which image to show in my Page_Load
() in ASP.NET. Something like:

void Page_Load()
{
if (Request.IsAuthenticated)
{
obj.src = "/graphics/TopSignOff.gif";
}
else
{
obj.src = "/graphics/TopSignOn.gif";
}
}

I am not sure, though, how to declare and/or find that
obj. Is it possible? Or should I choose a different
approach?

Thanks for the help.

VR
 
<div name="signOn" runat="server"><a href="etc"></div>
<div name="signOff" runat="server"><a href="etc"></div>

in Page_Load()
signOn.Visible = !Request.IsAuthenticated;
signOff.Visible = !signOn.Visible;

(You need to declare signOn and signOff as members of your class, protected
or public).


--
Pete
=============
http://www.DroopyEyes.com - Delphi source code
Audio compression components, Fast Strings, DIB Controls

Read or write article on just about anything
http://www.HowToDoThings.com
 
VR,

Either use a asp.net image control. Which will have the runat="server" tag
and means that it will be declared in the codebehind, or convert your html
image tab into a server control by adding the runat="server" tag to it.

The first way is probably easier (because the object's declaration will be
added to the code-behind page automatically). Just drop an "Image" from the
web form toolbox onto your page and you'll get code like this in the html.
Also in your code-behind page you'll have a new object declared: "Image1".

<asp:Image id="Image1" runat="server"></asp:Image>

The code-behind page's object declaration will look like:

Protected WithEvents Image1 As System.Web.UI.WebControls.Image

Now, simply use the same code you gave as an example setting the image
object's source.

Image1.ImageUrl = "/graphics/TopSignOff.gif";

You're other option is similar.

Add the runat="server" attribute to your image tag.

Give your image tag an id.

<img id="Image1" runat="server">

Declare a matching object on the code behind page.

Protected Image1 As System.Web.UI.HtmlControls.HtmlImage

Now set the source:

Image1.Attributes.Add("src", "/graphics/TopSignOn.gif")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Thanks for the help.

VR
-----Original Message-----
VR,

Either use a asp.net image control. Which will have the runat="server" tag
and means that it will be declared in the codebehind, or convert your html
image tab into a server control by adding the runat="server" tag to it.

The first way is probably easier (because the object's declaration will be
added to the code-behind page automatically). Just drop an "Image" from the
web form toolbox onto your page and you'll get code like this in the html.
Also in your code-behind page you'll have a new object declared: "Image1".

<asp:Image id="Image1" runat="server"></asp:Image>

The code-behind page's object declaration will look like:

Protected WithEvents Image1 As System.Web.UI.WebControls.Image

Now, simply use the same code you gave as an example setting the image
object's source.

Image1.ImageUrl = "/graphics/TopSignOff.gif";

You're other option is similar.

Add the runat="server" attribute to your image tag.

Give your image tag an id.

<img id="Image1" runat="server">

Declare a matching object on the code behind page.

Protected Image1 As System.Web.UI.HtmlControls.HtmlImage

Now set the source:

Image1.Attributes.Add("src", "/graphics/TopSignOn.gif")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche





.
 
Back
Top