child controls in a user control in a datalist

R

Roman

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)
 
D

Daniel Fisher\(lennybacon\)

That is because everytime a postback is fired (the button is clicked) the
datalist will be rebuild and the command of the button will not be
identified as code of the newly created button.
 
G

Guest

Hi,

1. Give a command name to the button.
2. When the button is clicked, the textbox should not be visible.

Hope it helps.

Prakash.C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top