TextBox.AddParsedSubObject(Object) Yöntem

Tanım

Özellik olarak yalnızca değişmez değer denetimlerinin eklenmesine izin vermek için geçersiz kılınmış Text .

protected:
 override void AddParsedSubObject(System::Object ^ obj);
protected override void AddParsedSubObject (object obj);
override this.AddParsedSubObject : obj -> unit
Protected Overrides Sub AddParsedSubObject (obj As Object)

Parametreler

obj
Object

Object Ayrıştırılmış öğeyi temsil eden bir.

Özel durumlar

obj türünde LiteralControldeğil.

Örnekler

Aşağıdaki kod örneği, ayrıştırılan nesne bir denetimse her zaman özelliği ayrıştırılmış nesnenin Text özelliğine ayarlayıp Text aksi takdirde bir özel durum oluşturacak şekilde özel bir Literal sunucu denetiminde yönteminin nasıl geçersiz kılındığını AddParsedSubObject gösterir.

Önemli

Bu örnekte, olası bir güvenlik tehdidi olan kullanıcı girişini kabul eden bir metin kutusu vardır. Varsayılan olarak, ASP.NET Web sayfaları kullanıcı girişinin betik veya HTML öğeleri içermediğini doğrular. Daha fazla bilgi için bkz . Betik Açıklarına Genel Bakış.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom TextBox - AddParsedSubObject - C# Example</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - AddParsedSubObject - C# Example</h3>
            
            <aspSample:CustomTextBoxAddParsedSubObject 
              id="TextBox1" 
              runat="server">Hello World!
            </aspSample:CustomTextBoxAddParsedSubObject>
            
        </form>
    </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Custom TextBox - AddParsedSubObject - VB.NET Example</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - AddParsedSubObject - VB.NET Example</h3>
            
            <aspSample:CustomTextBoxAddParsedSubObject id="TextBox1" 
             runat="server">Hello World!</aspSample:CustomTextBoxAddParsedSubObject>
        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomTextBoxAddParsedSubObject : System.Web.UI.WebControls.TextBox
  {
    protected override void AddParsedSubObject(object obj)
    {
      // If the object is a LiteralControl, then set this control's Text property.
      if (obj is System.Web.UI.LiteralControl) 
      {
        this.Text = ((System.Web.UI.LiteralControl)obj).Text;
      }
      else 
      {
        throw new System.Web.HttpException("You cannot have a child control of type " + obj.GetType().Name.ToString());
      }
    }
  }
}
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomTextBoxAddParsedSubObject
        Inherits System.Web.UI.WebControls.TextBox

        Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)

            ' If the object is a LiteralControl, then set this control's Text property.
            If TypeOf obj Is System.Web.UI.LiteralControl Then
                Me.Text = CType(obj, System.Web.UI.LiteralControl).Text
            Else
                Throw New System.Web.HttpException("You cannot have children controls of type " + obj.GetType().Name.ToString())
            End If
        End Sub
    End Class
End Namespace

Şunlara uygulanır

Ayrıca bkz.