using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//Loop for get DataField in CustomUserControl คือ ccTextBox
//loop
//{
//Print customUserControl.DataField.ToString
//}
//endloop
}
}
}
Partial Class ccTextbox
Inherits System.Web.UI.UserControl
Public Property DataField() As String
Get
Dim s As String = ViewState("DataField")
If Not IsDBNull(s) Then
Return s
Else
Return Me.Attributes("DataField")
End If
End Get
Set(value As String)
ViewState("DataField") = value
End Set
End Property
End Class
Partial Class Demo_CustomControl_TestUseCC
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
Dim st As String = ""
For Each cntl As Control In PlaceHolder1.Controls
If TypeOf cntl Is ccTextbox Then
st &= CType(cntl, ccTextbox).DataField
End If
Next
lbl_Result.Text = st
End Sub
End Class