DataBoundLiteralControl.Text プロパティ
アセンブリ: System.Web (system.web.dll 内)



カスタム コントロールを作成し、このコントロールを .aspx ファイル内から使用して、DataBoundLiteralControl オブジェクトのテキストを表示する方法を次のコード例に示します。このカスタム コントロールは DataBoundLiteralControl オブジェクトを取得し、Render メソッドを使用してテキスト プロパティを出力します。
Imports System Imports System.Web Imports System.Web.UI Namespace Samples.AspNet.VB.Controls Public Class MyControlVB Inherits Control <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub Render(Output As HtmlTextWriter) ' Checks if a DataBoundLiteralControl object is present. If HasControls() And TypeOf Controls(0) Is DataBoundLiteralControl Then ' Obtains the DataBoundLiteralControl instance. Dim boundLiteralControl As DataBoundLiteralControl = CType(Controls(0), DataBoundLiteralControl) ' Retrieves the text in the boundLiteralControl object. Dim text As String = boundLiteralControl.Text output.Write(("<h4>Your Message: " + text + "</h4>")) End If End Sub 'Render End Class 'MyControl End Namespace 'MyUserControl
using System; using System.Web; using System.Web.UI; namespace Samples.AspNet.CS.Controls { public class MyControl : Control { [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void Render(HtmlTextWriter output) { // Checks if a DataBoundLiteralControl object is present. if ( (HasControls()) && (Controls[0] is DataBoundLiteralControl) ) { // Obtains the DataBoundLiteralControl instance. DataBoundLiteralControl boundLiteralControl = (DataBoundLiteralControl)Controls[0]; // Retrieves the text in the boundLiteralControl object. String text = boundLiteralControl.Text; output.Write("<h4>Your Message: " +text+"</h4>"); } } } }
/*File name: myDataBoundLiteralControl.jsl */ import System.*; import System.Web.*; import System.Web.UI.*; public class MyControl extends Control { protected void Render(HtmlTextWriter output) { // Checks if a DataBoundLiteralControl object is present. if (HasControls() && get_Controls().get_Item(0) instanceof DataBoundLiteralControl) { // Obtains the DataBoundLiteralControl instance. DataBoundLiteralControl boundLiteralControl = (DataBoundLiteralControl)get_Controls().get_Item(0); // Retrieves the text in the boundLiteralControl object. String text = boundLiteralControl.get_Text(); output.Write("<h4>Your Message: " + text + "</h4>"); } } //Render } //MyControl
Visual Basic コンパイラ (vbc.exe) または C# コンパイラ (csc.exe) を使用して、コントロールをコンパイルできます。結果として得られた .dll ファイルは、次のコード例に示すように、Web プロジェクトの Bin ディレクトリに配置する必要があります。
vbc /r:System.dll /r:System.Web.dll /t:library /out:myWebAppPath/bin/vb_myDataBoundLiteralControl.dll myDataBoundLiteralControl.vb
カスタム コントロールを作成し、.aspx ファイルに登録して使用する方法を次のコード例に示します。
<%@ Page Language="VB" %> <%@ Register TagPrefix="MyControlSample" Namespace="Samples.AspNet.VB.Controls" %> <html> <head> <script language="VB" runat="server"> Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs) Page.DataBind() End Sub </script> </head> <body> <h3> DataBoundLiteralControl Example </h3> <form method="post" runat="server" ID="Form1"> <asp:Label id="Label1" Text="This is a string retrieved from 'DataBoundLiteralControl'" Runat="server" Visible="False"></asp:Label> <MyControlSample:MyControlVB id="MyControl" runat="server"> <%# Label1.Text %> </MyControlSample:MyControlVB> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Register TagPrefix="MyControlSample" Namespace="Samples.AspNet.CS.Controls" %> <html> <head> <script language="C#" runat="server"> void Page_Load(Object Sender, EventArgs e) { Page.DataBind(); } </script> </head> <body> <h3> DataBoundLiteralControl Example </h3> <form method="post" runat="server" ID="Form1"> <asp:Label id="Label1" Text="This is a string retrieved from 'DataBoundLiteralControl'" Runat="server" Visible="False"></asp:Label> <MyControlSample:MyControl id="MyControl" runat="server"> <%# Label1.Text %> </MyControlSample:MyControl> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDataBoundLiteralControl.Text プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataBoundLiteralControl.Text プロパティのページへのリンク