By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,676 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,676 IT Pros & Developers. It's quick & easy.

user control and setting properties of child controls

P: n/a
I have built a simple user control that contains 2 buttons, a text box and a
dropdownlist. When a button is clicked it sets the visible property
of the textbox/dropdownlist and the button. ie the buttons allow me to
toggle between the textbox and the dropdownlist. This works fine when the
control
is placed on the page but when it is placed inside a datalist, ie the
itemtemplate, the onclick events for the buttons fire but the visibility is
not set.

How do I change the visibility of the child controls of a user control when
it is placed inside a datalist?

I have placed some code below in the hope that it helps.Thanks in advance.
***************this is my user control************************
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="ComboBox.ascx.vb" Inherits="globalDocWeb.ComboBoxUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<nobr>
<asp:textbox id="cmbTxt" runat="server" ></asp:textbox>
<asp:button id="btnDdl" runat="server" Text="ddl"
Width="32px"></asp:button>
</nobr>

<nobr><asp:dropdownlist visible=False id="cmbDdl" runat="server" >
</asp:dropdownlist><asp:button visible=False id="btnTxt" runat="server"
Text="txt" Width="32px"></asp:button>
</nobr>

***********this is the code behind of the user
control****************************

Public Class ComboBoxUserControl
Inherits System.Web.UI.UserControl
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents cmbDdl As System.Web.UI.WebControls.DropDownList
Protected WithEvents cmbTxt As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDdl As System.Web.UI.WebControls.Button
Protected WithEvents btnTxt As System.Web.UI.WebControls.Button

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub

Private Sub btnDdl_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDdl.Click
cmbTxt.Visible = False
btnDdl.Visible = False
cmbDdl.Visible = True
btnTxt.Visible = True
End Sub

Private Sub btnTxt_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnTxt.Click
cmbTxt.Visible = True
btnDdl.Visible = True
cmbDdl.Visible = False
btnTxt.Visible = False
End Sub
End Class

*********this is how I access the control within the itemdatabound event of
the datalist*******

Dim list As ComboBoxUserControl = CType(e.Item.FindControl("Name"),
ComboBoxUserControl)
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Roman" <sp**@spam.de> wrote in message news:cr**********@online.de...
I have built a simple user control that contains 2 buttons, a text box and
a dropdownlist. When a button is clicked it sets the visible property
of the textbox/dropdownlist and the button. ie the buttons allow me to
toggle between the textbox and the dropdownlist. This works fine when the
control
is placed on the page but when it is placed inside a datalist, ie the
itemtemplate, the onclick events for the buttons fire but the visibility
is not set.


Haven't I seen this post before? Please don't cross-post.

John Saunders
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.