problems with my UserControl

Discussion in 'ASP .Net Web Controls' started by Magnus Pesch, Jul 9, 2004.

  1. Magnus Pesch

    Magnus Pesch Guest

    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?

    >


    > Thanx.


    > 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


    > Get


    > Return Text


    > End Get


    > Set(ByVal Value As String)


    > Text = Value


    > End Set


    > 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"


    > Panel1.Controls.Add(c1)


    > 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"


    > End Sub


    > End Class


    >


    > *** Ende WebForm
     
    Magnus Pesch, Jul 9, 2004
    #1
    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. huobazi
    Replies:
    1
    Views:
    741
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    443
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,581
  4. Phl
    Replies:
    2
    Views:
    548
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
    Nov 18, 2004
  5. Fabiano
    Replies:
    2
    Views:
    651
    =?Utf-8?B?c3Jpbmk=?=
    Jun 3, 2005
Loading...

Share This Page