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

composite control problems

P: n/a
I have created a composite control in C# which shows a DropDownList with 4
items and when one is selected a relevant message appears in a TextBox. This
works fine.

I then tried to recreate the control using VB.NET, but when I select an item
from the list it posts back to the server and resets the list to the default
value. Nothing appears in the TextBox. AutoeventWireUp is set to false in
both projects, AutoPostBack for the DropDownList is set to true in the
control and I am using the same html to register the control.

Does anyone know of any issues when using different languages to create
composite controls?
Jul 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The problem seems to be doesn't connected with language issue. It could
be the reason that your ViewState doesn't seems to be maintaining the
values of the control. Did you tried to set True for EnableViewState
property of the controls.

Check for whether the ViewState is set to false in the page where you
are using the composite control.

If you still find problem, please put some of your source code here so
that we can check it.

--
Vadivel Kumar
http://www.vadivelk.net
va**@online.vadivelk.net (remove "online.")

cashdeskmac wrote:
I have created a composite control in C# which shows a DropDownList with 4
items and when one is selected a relevant message appears in a TextBox. This
works fine.

I then tried to recreate the control using VB.NET, but when I select an item
from the list it posts back to the server and resets the list to the default
value. Nothing appears in the TextBox. AutoeventWireUp is set to false in
both projects, AutoPostBack for the DropDownList is set to true in the
control and I am using the same html to register the control.

Does anyone know of any issues when using different languages to create
composite controls?
Jul 20 '06 #2

P: n/a
Hi Vadival,

here is the code to create the control:

Private box1 As New TextBox
Private WithEvents ddl As New DropDownList
Private lbl As New Label

Protected Overrides Sub CreateChildControls()
'Set some properties of the controls
ddl.Items.Add("One")
ddl.Items.Add("Two")
ddl.Items.Add("Three")
ddl.Items.Add("Four")
ddl.AutoPostBack = True
lbl.Text = Me.Text
'Add these controls to the controls collection
Me.Controls.Add(lbl)
'This gives us a new line
Me.Controls.Add(New LiteralControl("<br>"))
Me.Controls.Add(ddl)
Me.Controls.Add(New LiteralControl("<br><br>"))
Me.Controls.Add(box1)
AddHandler ddl.SelectedIndexChanged, AddressOf
ddl_SelectedIndexChanged
End Sub

Private Sub ddl_SelectedIndexChanged( _
ByVal sender As Object, ByVal e As EventArgs)
Me.EnsureChildControls()
box1.Text = "You chose " & ddl.SelectedItem.Text
End Sub

I have this in the html of the page:

<%@ Register TagPrefix="cc1" Namespace="CompositeControl"
Assembly="CompositeControl" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" action="WebForm1.aspx" runat="server">
<cc1:WebCustomControl1 id="WebCustomControl11"
runat="server" Text="Choose a number:"></cc1:WebCustomControl1>
</form>
</body>
</HTML>
Notice anything which might be causing the problem?

Jul 20 '06 #3

P: n/a


Found the problem: I wasn't implementing INamingContainer in the control.

Sorted now.
Jul 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.