ASP. NET self-study-htmllink

Source: Internet
Author: User
ArticleDirectory
    • Attribute Value

Allow programming to access the HTML <link> element on the server.

The followingCodeThe example shows how to declare the htmllink control programmatically and define its properties.

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class htmllinkcs_aspx
{
Void page_init (Object sender, eventargs E)
{
// Create an instance of htmllink.
Htmllink myhtmllink = new htmllink ();
Myhtmllink. href = "stylesheet.css ";
Myhtmllink. Attributes. Add ("rel", "stylesheet ");
Myhtmllink. Attributes. Add ("type", "text/CSS ");

// Add the instance of htmllink to the Head1.controls. Add (myhtmllink );
}
}

 

Htmllink. href attributes

The href attribute specifies the URL target for the link specified in the htmllink control. You can use this attribute to specify the position of an external Cascading Style Sheet (CSS.

The following code example shows how to set the href attribute to save Cascading Style Sheets (CSS) in the directory where the webpage is located ).

Htmlcontrol. Attributes attributes

Obtains the set of all attribute names and value pairs represented on the server control tag on the ASP. NET page.

C #

 
Public attributecollection attributes {Get ;}

Attribute Value

System. Web. UI. attributecollection object, which contains all attribute names and value pairs marked by server controls on the webpage.

You can use this property to access the attribute of the HTML Server Control programmatically ). All HTML server controls store their attributes in control. viewstate attributes.

The HTML attribute is treated as a property on the HTML server control to which the. NET Framework belongs ).


The following code example demonstrates how to use the attributes attribute to determine the attribute of the htmlselect control ).

<% @ Page Language = "C #" autoeventwireup = "true" %>

<HTML>

<Script language = "C #" runat = "server">

Void page_load (Object sender, eventargs E)

{

Message. innerhtml = "<H4> the select box's attributes collection contains: </H4> ";

Ienumerator keys = select. Attributes. Keys. getenumerator ();

While (Keys. movenext ())

{

String key = (string) keys. Current;

Message. innerhtml + = Key + "=" + select. attributes [Key] + "<br> ";

}

}

</SCRIPT>

<Body>

<H3> htmlcontrol attribute collection example

Make a selection:

<Select id = "select"

Style = "Font: 12pt verdana;

Background-color: yellow;

Color: red ;"

Runat = "server">

<Option> Item 1 </option>

<Option> Item 2 </option>

<Option> Item 3 </option>

</SELECT>

<P>

<Span id = "message" maintainstate = "false" runat = "server"/>

</Body>

</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.