child controls in a user control in a datalist

Discussion in 'ASP .Net' started by Roman, Jan 3, 2005.

  1. Roman

    Roman Guest

    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)
    Roman, Jan 3, 2005
    #1
    1. Advertising

  2. 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.

    --
    Daniel Fisher(lennybacon)
    MCP ASP.NET C#
    Blog: http://www.lennybacon.com/


    "Roman" <> wrote in message news:crcctn$735$...
    >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)
    >
    Daniel Fisher\(lennybacon\), Jan 3, 2005
    #2
    1. Advertising

  3. 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

    "Daniel Fisher(lennybacon)" wrote:

    > 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.
    >
    > --
    > Daniel Fisher(lennybacon)
    > MCP ASP.NET C#
    > Blog: http://www.lennybacon.com/
    >
    >
    > "Roman" <> wrote in message news:crcctn$735$...
    > >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)
    > >

    >
    >
    >
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=, Jan 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,847
  2. Replies:
    0
    Views:
    2,214
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,086
    David Schwartz
    Dec 9, 2003
  4. Replies:
    0
    Views:
    194
  5. Roman
    Replies:
    2
    Views:
    248
    Roman
    Jan 4, 2005
Loading...

Share This Page