Create A Link

You can work with the anchor tag, <a>, programmatically by using the HTMLAnchor control. This control gives you the ability to both set and get information from the <a> tags that you create on your ASP.NET pages. When using the <a> tag as an HTML server control, it must have an opening and closing tag.

The href attribute for the anchor tag is the URL that the user gets sent to when clicking the anchor tag. The anchor tag surrounds the text, or HTML, that will be hyperlinked in the user's Web browser. To build your anchor tags dynamically, you can use the combination of a data repeater and data binding to create parts of the anchor tag. To properly configure a bound anchor tag, you should bind the href attribute and the text between the <a> and </a> tags.

While the page is loading, you can set the properties for an HTMLAnchor control. For example, you can set the href property to equal the URL that you want the user to navigate upon clicking the link. You can also set the InnerText property of the HTMLAnchor control. This text is what the user clicks to request another resource on the Web server.

CREATE A LINK

Jg Untitled - Notepad

-Ifllxl

File Edit Format Help

•¡HTMLs <HEAD>

A

•¡FONT FACE ="Verdana">

<H3>Welcometo mvlifetimecioals.com</H3>l

-

Be sure to visit the Home Faciei 1—

-=/FONT=-■=/BODY=> -=/HTML=-

J

J

GenericTemplate.aspx template from the Code Templates directory.

H Add a heading for the page.

Q Open the

GenericTemplate.aspx template from the Code Templates directory.

H Add a heading for the page.

Add a message to the user.

_Q Add a form to the page with a RUNAT attribute set to "Server".

Q Place an anchor with a RUNAT attribute set to "Server" on the page for the user to click.

_Q Add a form to the page with a RUNAT attribute set to "Server".

Q Place an anchor with a RUNAT attribute set to "Server" on the page for the user to click.

You can override the redirect of the HTMLAnchor control by implementing the

ServerClick event.

RUNAT="Server">

Example:

<SCRIPT LANGUAGE=MC#"

void aWebsite_OnClick(object Source, EventArgs e) {

aWebsite.InnerText="You clicked?"; </SCRIPT>

<A ID="aWebsite" RUNAT="Server"

HREF="http://www.mylifetimegoals.com"

onServerClick="aWebsite_OnClick">

Go To Home Page for My Lifetime Goals Website

You can set the attributes for the anchor tag in the HTML as well.

Example:

<A ID="aWebsite" RUNAT="Server" HREF="http://www.mylifetimegoals.com">

Go To Home Page for My Lifetime Goals Website

L-0 Add the Page_Load function between the <HEAD> tags.

Q Set the HREF property of the anchor on the form.

L-0 Add the Page_Load function between the <HEAD> tags.

Q Set the HREF property of the anchor on the form.

LQ Set the InnerText property of the anchor on the form.

| File Edit View Favorites Tools Help M 'il

| <r> Back - -r [jjj | fg Personal Bar Search Qy Favorites 0 I|

Address |<|] http7/localhost/H T M LAnchor. aspx

■»■j ¿£Go Links w

Welcome to mylifetimegoals.com

| Be sure to visit the Home Page

Go To Home Paoe for My Lifetime Goals Website 1

J

Done

¡ÜSt Local intranet |

• Save the file and request it from the Web server.

Note: See pages 20 to 25 for instructions on saving a file to the Web server and then requesting the file using the IIS Admin.

■ The anchor appears properly.

Was this article helpful?

0 0

Post a comment