M
Moldy
I am using a Custom Control on a page which renders a button control
if required. I need to access the child button control's properties
(i.e. UniqueID) on the page but cannot get them to come through on
first load of the page, only on postback. Can anyone help!
Code is below
On first load, only the button is displayed, click the button and the
UniqueID appears.
TIA
Moldy
********** START CODE FOR CUSTOM CONTROL **********
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class ButtonControl
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim bMyButton As Boolean
<Browsable(True), DefaultValue(False)> Public Property
ShowMyButton() As Boolean
Get
Return bMyButton
End Get
Set(ByVal Value As Boolean)
bMyButton = Value
End Set
End Property
Public myButton As New Button()
Protected Overrides Sub CreateChildControls()
With myButton
.Text = "Click Me!"
.Visible = False
End With
Controls.Add(myButton)
End Sub
Private Sub ButtonControl_PreRender(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.PreRender
If bMyButton Then
myButton.Visible = True
Else
myButton.Visible = False
End If
End Sub
End Class
********** END CODE FOR CUSTOM CONTROL **********
********** START CODE FOR ASPX PAGE **********
<%@ Register TagPrefix="CompControl" Namespace="CompControl"
Assembly="CompControl" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Default.aspx.vb" Inherits="ChildControlTest.WebForm1"%>
<html>
<body>
<form id="Form1" method="post" runat="server">
<compcontrol:buttoncontrol
id="myButtonControl" runat="server"></compcontrol:buttoncontrol>
</form>
</body>
</html>
********** END CODE FOR ASPX PAGE **********
********** START CODE FOR ASPX.VB PAGE **********
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents myButtonControl As
CompControl.ButtonControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
myButtonControl.ShowMyButton = True
Response.Write(myButtonControl.myButton.UniqueID)
End Sub
End Class
********** END CODE FOR ASPX.VB PAGE **********
if required. I need to access the child button control's properties
(i.e. UniqueID) on the page but cannot get them to come through on
first load of the page, only on postback. Can anyone help!
Code is below
On first load, only the button is displayed, click the button and the
UniqueID appears.
TIA
Moldy
********** START CODE FOR CUSTOM CONTROL **********
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class ButtonControl
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer
Dim bMyButton As Boolean
<Browsable(True), DefaultValue(False)> Public Property
ShowMyButton() As Boolean
Get
Return bMyButton
End Get
Set(ByVal Value As Boolean)
bMyButton = Value
End Set
End Property
Public myButton As New Button()
Protected Overrides Sub CreateChildControls()
With myButton
.Text = "Click Me!"
.Visible = False
End With
Controls.Add(myButton)
End Sub
Private Sub ButtonControl_PreRender(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.PreRender
If bMyButton Then
myButton.Visible = True
Else
myButton.Visible = False
End If
End Sub
End Class
********** END CODE FOR CUSTOM CONTROL **********
********** START CODE FOR ASPX PAGE **********
<%@ Register TagPrefix="CompControl" Namespace="CompControl"
Assembly="CompControl" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Default.aspx.vb" Inherits="ChildControlTest.WebForm1"%>
<html>
<body>
<form id="Form1" method="post" runat="server">
<compcontrol:buttoncontrol
id="myButtonControl" runat="server"></compcontrol:buttoncontrol>
</form>
</body>
</html>
********** END CODE FOR ASPX PAGE **********
********** START CODE FOR ASPX.VB PAGE **********
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents myButtonControl As
CompControl.ButtonControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
myButtonControl.ShowMyButton = True
Response.Write(myButtonControl.myButton.UniqueID)
End Sub
End Class
********** END CODE FOR ASPX.VB PAGE **********