This documentation is archived and is not being maintained.

HtmlTextWriter.EncodeUrl Method

Performs minimal URL encoding by converting spaces passed in the url parameter to %20.

[Visual Basic]
Protected Function EncodeUrl( _
   ByVal url As String _
) As String
[C#]
protected string EncodeUrl(
 string url
);
[C++]
protected: String* EncodeUrl(
 String* url
);
[JScript]
protected function EncodeUrl(
   url : String
) : String;

Parameters

url
The URL to be encoded.

Return Value

The encoded URL.

Remarks

URL encoding of a character consists of a % symbol, followed by the two-digit hexadecimal representation (case-insensitive) of the ISO-Latin code point for the character. The hexadecimal representation of a space is 20.

Example

[Visual Basic] 
' If an Anchor element is being rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href
' attribute and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
   If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
      AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
   End If
End If

[C#] 
// If an Anchor element is being rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href
// attribute and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if(TagKey == HtmlTextWriterTag.A)
{
   if(!IsAttributeDefined(HtmlTextWriterAttribute.Href))
   {
      AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
   }
}

[C++] 
// If an Anchor element is being rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag::A) {
   if (!IsAttributeDefined(HtmlTextWriterAttribute::Href)) {
      AddAttribute(S"href", EncodeUrl(S"http://www.cohowinery.com"));
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace

Show: