Uredi

Deli z drugimi prek


HtmlTextWriter.Write Method

Definition

Writes the specified data type to the output stream, along with any pending tab spacing.

Overloads

Write(Boolean)

Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

Write(Char)

Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

Write(Char[])

Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

Write(Double)

Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

Write(Int32)

Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

Write(Int64)

Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

Write(Object)

Writes the text representation of an object to the output stream, along with any pending tab spacing.

Write(Single)

Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

Write(String)

Writes the specified string to the output stream, along with any pending tab spacing.

Write(String, Object)

Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

Write(String, Object[])

Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object[]) method.

Write(Char[], Int32, Int32)

Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

Write(String, Object, Object)

Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object, Object) method.

Write(Boolean)

Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

public:
 override void Write(bool value);
public override void Write (bool value);
override this.Write : bool -> unit
Public Overrides Sub Write (value As Boolean)

Parameters

value
Boolean

The Boolean to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Char)

Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

public:
 override void Write(char value);
public override void Write (char value);
override this.Write : char -> unit
Public Overrides Sub Write (value As Char)

Parameters

value
Char

The Unicode character to write to the output stream.

Examples

The following code example demonstrates using the Write method to end the opening tag of an <img> element by using the TagRightChar constant.

This code example renders the following markup:

<img alt="A custom image">

</img>

// Create a manually rendered <img> element
// that contains an alt attribute.
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", "A custom image.");
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("img");
' Create a manually rendered <img> element
' that contains an alt attribute.
writer.WriteBeginTag("img")
writer.WriteAttribute("alt", "A custom image.")
writer.Write(HtmlTextWriter.TagRightChar)
writer.WriteEndTag("img")

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Char[])

Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

public:
 override void Write(cli::array <char> ^ buffer);
public override void Write (char[] buffer);
override this.Write : char[] -> unit
Public Overrides Sub Write (buffer As Char())

Parameters

buffer
Char[]

The array of Unicode characters to write to the output stream.

Examples

This section provides two code examples. The first one demonstrates how to create an array of characters. The second one demonstrates how to use the array.

These code examples generate the following markup:

<label>

hello world

</label>

The following code example demonstrates how to create an array of characters that spell out hello world. Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};
Private testChars() As Char = _
    {"h"c, "e"c, "l"c, "l"c, "o"c, _
    HtmlTextWriter.SpaceChar, "w"c, "o"c, "r"c, "l"c, "d"c}

The following code example demonstrates how to use the Write method to render the hello world character array created in the preceding code example to a page, when the control that contains this example code is included in a page.

// Render a character array as the 
// contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars);
writer.RenderEndTag();
' Render a character array as the 
' contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write(testChars)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Double)

Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

public:
 override void Write(double value);
public override void Write (double value);
override this.Write : double -> unit
Public Overrides Sub Write (value As Double)

Parameters

value
Double

The double-precision floating-point number to write to the output stream.

Examples

The following code example shows how to use the Write method to render the value of the Double.MaxValue field.

This code example generates the following markup:

<label>

1.79769313486232E+308

</label>

// Use the Write(Double) method to render
// the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(Double.MaxValue);
writer.RenderEndTag();
' Use the WriteLine(Double) method to render
' the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.WriteLine(Double.MaxValue)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Int32)

Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

public:
 override void Write(int value);
public override void Write (int value);
override this.Write : int -> unit
Public Overrides Sub Write (value As Integer)

Parameters

value
Int32

The 32-byte signed integer to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Int64)

Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

public:
 override void Write(long value);
public override void Write (long value);
override this.Write : int64 -> unit
Public Overrides Sub Write (value As Long)

Parameters

value
Int64

The 64-byte signed integer to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Object)

Writes the text representation of an object to the output stream, along with any pending tab spacing.

public:
 override void Write(System::Object ^ value);
public override void Write (object value);
override this.Write : obj -> unit
Public Overrides Sub Write (value As Object)

Parameters

value
Object

The object to write to the output stream.

Examples

The following code example shows how to use the Write method to render the value of the CultureInfo.CurrentCulture property.

This code example generates the following markup:

This is a rendered CultureInfo object.

<bold>

The value of the CurrentCulture property:

</bold>

// Use the Write method to render an arbitrary
// object, in this case a CultureInfo object. 
writer.Write("This is a rendered CultureInfo Object.");
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(CultureInfo.CurrentCulture);
writer.RenderEndTag();
' Use the Write method to render an arbitrary
' object, in this case a CultureInfo object.
writer.Write("This is a rendered CultureInfo Object.")
writer.RenderBeginTag(HtmlTextWriterTag.B)
writer.Write(CultureInfo.CurrentCulture)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Single)

Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

public:
 override void Write(float value);
public override void Write (float value);
override this.Write : single -> unit
Public Overrides Sub Write (value As Single)

Parameters

value
Single

The single-precision floating-point number to write to the output stream.

Examples

The following code example demonstrates how to use the Write method to render the value of the Single.Epsilon field, which is the smallest possible value of the Single structure.

This code example generates the following markup:

<b>

1.401298E-45

</b>

// Use the Write(Single) method to render the
// Epsilon field of the Single structure. 
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(Single.Epsilon);
writer.RenderEndTag();
' Use the Write(Single) method to render the
' Epsilon field of the Single structure. 
writer.RenderBeginTag(HtmlTextWriterTag.B)
writer.Write(Single.Epsilon)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(String)

Writes the specified string to the output stream, along with any pending tab spacing.

public:
 override void Write(System::String ^ s);
public override void Write (string s);
override this.Write : string -> unit
Public Overrides Sub Write (s As String)

Parameters

s
String

The string to write to the output stream.

Examples

The following code example demonstrates how to use the Write method to render a string between the opening and closing tags of a custom markup element.

This code example generates the following markup:

<MyTag>

Contents of MyTag

</MyTag>

// Create a non-standard tag.
writer->RenderBeginTag( "MyTag" );
writer->Write( "Contents of MyTag" );
writer->RenderEndTag();
writer->WriteLine();
// Create a non-standard tag.
writer.RenderBeginTag("MyTag");
writer.Write("Contents of MyTag");
writer.RenderEndTag();
writer.WriteLine();
' Create a non-standard tag.
writer.RenderBeginTag("MyTag")
writer.Write("Contents of MyTag")
writer.RenderEndTag()
writer.WriteLine()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(String, Object)

Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

public:
 override void Write(System::String ^ format, System::Object ^ arg0);
public override void Write (string format, object arg0);
override this.Write : string * obj -> unit
Public Overrides Sub Write (format As String, arg0 As Object)

Parameters

format
String

A string that contains zero or more format items.

arg0
Object

An object to format.

Examples

The following code example shows how to use the Write method to render a formatted string with the value of the CurrentCulture property.

// Use the Write(string, object) method to
// render a formatted string and an object in it.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}",
    CultureInfo.CurrentCulture);
writer.RenderEndTag();
' Use the Write(string, object) method to
' render a formatted string and an object in it.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The current cultural settings are {0}.", _
    CultureInfo.CurrentCulture)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(String, Object[])

Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object[]) method.

public:
 override void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public override void Write (string format, params object[] arg);
override this.Write : string * obj[] -> unit
Public Overrides Sub Write (format As String, ParamArray arg As Object())

Parameters

format
String

A string that contains zero or more format items.

arg
Object[]

An object array to format.

Examples

This section contains two code examples. The first one demonstrates how to render a formatted string and the contents of an array. The second one demonstrates how to declare the array.

The following code example shows how to use the Write method to render a formatted string and the contents of an object array, named curPriceTime. The method call renders the second member of the array before it renders the first member.

// Render a formatted string and the
// text representation of an object array,
// myObjectArray, as the contents of
// a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The trade value at {1} is ${0}.", curPriceTime);
writer.RenderEndTag();
' Render a formatted string and the
' text representation of an object array,
' myObjectArray, as the contents of
' a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The trade value at {1} is ${0}.", curPriceTime)
writer.RenderEndTag()

The following code example demonstrates declaring the curPriceTime object array.

private object[] curPriceTime = {4.25, DateTime.Now};
Private curPriceTime() As Object = {4.25, DateTime.Now}

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(Char[], Int32, Int32)

Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

public:
 override void Write(cli::array <char> ^ buffer, int index, int count);
public override void Write (char[] buffer, int index, int count);
override this.Write : char[] * int * int -> unit
Public Overrides Sub Write (buffer As Char(), index As Integer, count As Integer)

Parameters

buffer
Char[]

The array of characters from which to write text to the output stream.

index
Int32

The index location in the array where writing begins.

count
Int32

The number of characters to write to the output stream.

Examples

This section provides two code examples. The first one demonstrates how to create a character array. The second one demonstrates how to use the array.

These code examples generate the following markup:

<label>

hello

</label>

The following code example shows how to create an array of characters that spell out hello world. Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};
Private testChars() As Char = _
    {"h"c, "e"c, "l"c, "l"c, "o"c, _
    HtmlTextWriter.SpaceChar, "w"c, "o"c, "r"c, "l"c, "d"c}

The following portion of the code example uses the index and count parameters of the Write method to render the first five characters of the array created in the preceding example.

// Render a subarray of a character array
// as the contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars, 0, 5);
writer.RenderEndTag();
' Render a subarray of a character array
' as the contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write(testChars, 0, 5)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

Write(String, Object, Object)

Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object, Object) method.

public:
 override void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public override void Write (string format, object arg0, object arg1);
override this.Write : string * obj * obj -> unit
Public Overrides Sub Write (format As String, arg0 As Object, arg1 As Object)

Parameters

format
String

A string that contains zero or more format items.

arg0
Object

An object to format.

arg1
Object

An object to format.

Examples

The following code example shows how to use the Write method to render a formatted string and the values of the CurrentCulture and Today properties.

// Use the Write(string,object,object) method to
// render a formatted string and two objects 
// in the string.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}. Today's date is {1}.",
    CultureInfo.CurrentCulture, DateTime.Today);
writer.RenderEndTag();
' Use the Write(string,object,object) method to
' render a formatted string and two objects 
' in the string.
writer.RenderBeginTag(HtmlTextWriterTag.Label)
writer.Write("The current cultural settings are {0}. Today's date is {1}.", _
    CultureInfo.CurrentCulture, DateTime.Today)
writer.RenderEndTag()

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to