composite control problems

G

Guest

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?
 
V

Vadivel Kumar

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

Guest

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?
 
G

Guest

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

Sorted now.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top