473,769 Members | 7,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

child controls in a user control in a datalist

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="Com boBox.ascx.vb" Inherits="globa lDocWeb.ComboBo xUserControl"
TargetSchema="h ttp://schemas.microso ft.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:drop downlist visible=False id="cmbDdl" runat="server" >
</asp:dropdownlis t><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 ComboBoxUserCon trol
Inherits System.Web.UI.U serControl
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents cmbDdl As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents cmbTxt As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnDdl As System.Web.UI.W ebControls.Butt on
Protected WithEvents btnTxt As System.Web.UI.W ebControls.Butt on

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
End Sub

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

Private Sub btnTxt_Click(By Val sender As Object, ByVal e As
System.EventArg s) 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 ComboBoxUserCon trol = CType(e.Item.Fi ndControl("Name "),
ComboBoxUserCon trol)
Nov 19 '05 #1
2 2308
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(lennybac on)
MCP ASP.NET C#
Blog: http://www.lennybacon.com/
"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.

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="Com boBox.ascx.vb" Inherits="globa lDocWeb.ComboBo xUserControl"
TargetSchema="h ttp://schemas.microso ft.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:drop downlist visible=False id="cmbDdl" runat="server" >
</asp:dropdownlis t><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 ComboBoxUserCon trol
Inherits System.Web.UI.U serControl
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents cmbDdl As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents cmbTxt As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnDdl As System.Web.UI.W ebControls.Butt on
Protected WithEvents btnTxt As System.Web.UI.W ebControls.Butt on

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
End Sub

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

Private Sub btnTxt_Click(By Val sender As Object, ByVal e As
System.EventArg s) 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 ComboBoxUserCon trol = CType(e.Item.Fi ndControl("Name "),
ComboBoxUserCon trol)

Nov 19 '05 #2
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(lennybac on)" 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(lennybac on)
MCP ASP.NET C#
Blog: http://www.lennybacon.com/
"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.

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="Com boBox.ascx.vb" Inherits="globa lDocWeb.ComboBo xUserControl"
TargetSchema="h ttp://schemas.microso ft.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:drop downlist visible=False id="cmbDdl" runat="server" >
</asp:dropdownlis t><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 ComboBoxUserCon trol
Inherits System.Web.UI.U serControl
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents cmbDdl As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents cmbTxt As System.Web.UI.W ebControls.Text Box
Protected WithEvents btnDdl As System.Web.UI.W ebControls.Butt on
Protected WithEvents btnTxt As System.Web.UI.W ebControls.Butt on

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
End Sub

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

Private Sub btnTxt_Click(By Val sender As Object, ByVal e As
System.EventArg s) 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 ComboBoxUserCon trol = CType(e.Item.Fi ndControl("Name "),
ComboBoxUserCon trol)


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2071
by: Roman | last post by:
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...
4
2266
by: Moojjoo | last post by:
Ok fellow C# developers: How do creat an instance of an object inside a dataset or datagrid. Example I need to have a placeholder inside a dataset. Any help would be great.
1
2672
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the DataList, I have a PlaceHolder control called phVariations. During the ItemDataBound event for dlProducts, I dynamically create a few DropDownLists (again, from a database) and .Add the DropDownList to the PlaceHolder control. That all works just...
4
3096
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a label, a radiobuttonlist, etc. I'm driving myself insane trying to figure out how to get
2
251
by: Jack | last post by:
Hi, If I just say have a user control which contains a datalist that displays information about different companies. The datalist contains an image for the company logo and some text describing the company. Now this is fine if each company template is the same BUT what if I want each company to be able to have there own template e.g. one having one logo and another have three. Now I could do this by creating one user control for each...
0
1845
by: Scott McChesney | last post by:
I have a problem I hope you folks can help me with. I have an application that is using a tab-based interface, with the ability for users to drag an item from a ListBox onto the tab control. This will create a new tab, put a new instance of the proper UserControl into the tab, and populate said UserControl with the data culled from the drop source. Because of the nature of this application, the particular UserControl that will be...
10
4029
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
2
2252
by: Amil Hanish | last post by:
I want to create a bunch of like user controls and display them in a DataList. Does anyone have a GOOD example of how to do this? I thought I had it...I added the user control to my <ItemTemplate>, created an array of user controls in my code behind and set the DataSource and called DataBind. But, all the user controls are unitialized when the page is rendered.
1
1739
by: Seth Petry-Johnson | last post by:
Is there a way to compile a user control into a redistributable assembly , but still have access to its child controls using the .Controls property? Here's what I mean: I have a user control that contains some child controls, mostly custom text boxes and such. If I load this control declaratively or using LoadControl(), I can access those child controls using the .Controls property.
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.