 |
|
get customUserControl ที่อยู่ใน PlaceHolder ต้องใช้อย่างไรครับ |
|
 |
|
|
 |
 |
|
เข้ามาดันกระทู้ครับ
ช่วยหน่อนนะครับ
|
 |
 |
 |
 |
Date :
2011-09-26 07:41:03 |
By :
chon2008 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อาจไม่เหมือนของจขกท
ccTextbox.ascx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ccTextbox.ascx.vb" Inherits="ccTextbox" %>
<asp:TextBox ID="myText" runat="server" />
ccTextbox.ascx.vb
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
TestUseCC.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestUseCC.aspx.vb" Inherits="Demo_CustomControl_TestUseCC" %>
<%@ Register TagPrefix="aspw" TagName="uTextBox" Src="~/Demo/CustomControl/ccTextbox.ascx" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="frmMain" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
<div>
<aspw:uTextBox id="ccText1" DataField="Field1" runat="server" />
<aspw:uTextBox id="ccText2" DataField="Field2" runat="server" />
</div>
</asp:PlaceHolder>
<asp:Button ID="btnSubmit" runat="server" Text="Test" /><br />
<asp:Label ID="lbl_Result" runat="server" />
</form>
</body>
</html>
TestUseCC.aspx.vb
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
|
ประวัติการแก้ไข 2011-09-26 09:21:27 2011-09-26 09:25:44
 |
 |
 |
 |
Date :
2011-09-26 09:20:40 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ไม่รู้จะใช้ประโยชน์ได้หรือไม่
ผลลัพธ์

|
ประวัติการแก้ไข 2011-09-26 09:23:49
 |
 |
 |
 |
Date :
2011-09-26 09:23:05 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คล้ายๆกันมากเลยครับ แต่มีจุดต่างกันตรงที่ผมไปสร้าง customUserControl เป็นอีกโปรเจค และใช้ asp .net server control
ขอบคุณมานะครับที่เข้ามาช่วย
|
 |
 |
 |
 |
Date :
2011-09-27 10:36:58 |
By :
chon2008 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|