problems with my UserControl

M

Magnus Pesch

Sorry,

I thought i would be in an german NG. I will try to translate...

i have made a UserControl (later there should be some controls in it) as
ascx-file (in Visual Studio 2003) and i am loading it in a normal WebForm.
In this UserControl should be properties (and later functions) which should
be changed (called) in the WebForm.

When I open the WebForm anythinf is ok.

But when i want to change the property (when the WebForm is already loaded)
and a PostBack is made, there is no change in the control from the
UserControl.Why? What can i do?

At the bottom there is my coding - there i used the property just for the
Text in a TextBox.

It would be nice, if anyone can help me with this. Maybe i must implement
IPostBackEventHandler...? How does this work?
Greetings from Germany, Magnus


My Coding:
*** CodeBehind UserControl

Public Class TestControl
Inherits System.Web.UI.UserControl

Private Text As String

Public Sub New()
Text = "nicht gesetzt"
End Sub

Public Sub New(ByVal Bezeichnung)
Text = Bezeichnung
End Sub

Public Property Bezeichnung() As String

Return Text
Set(ByVal Value As String)
Text = Value
End Property
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
TextBoxControl.Text = Text
End Class


*** Ende UserControl



*** Call in WebForm
Public Class WebForm1
Inherits System.Web.UI.Page
Dim c1 As UserControl = LoadControl("TestControl.ascx")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim c1 as UserControl = LoadControl("TestControl.ascx")
CType(c1, TestControl).Bezeichnung = "jetzt Text definiert"

End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
CType(c1, TestControl).Bezeichnung = "Text geändert"
 

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,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top