Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page.

Discussion in 'ASP .Net Web Controls' started by Kiran More, Nov 13, 2006.

  1. Kiran More

    Kiran More Guest

    I have created a lable in the InfoMessageBox.ascx control.
    This control in used in Master Page.

    One Page is designed by making use of this Master Page.
    This ASPX is having another user control.

    This user control has got one buttong which on click makes database call.

    The response returned after clicking the above button, i.e. either Error or Success, the label from InfoMessageBox will be set.

    Now I am unable to access the LABEL control Which is inside InfoMessageBox.ASCX which is used inside the Master Page.

    Please help me in this.

    kiran
     
    Kiran More, Nov 13, 2006
    #1
    1. Advertising

  2. Kiran More

    MikeS Guest

    Re: Accessing USER CONTROL which is inside Masterpage through Another USER Control inside normal page.

    Some may suggest you do a Master.FindControl to get the master pages
    label control to set its properties directly.

    But maybe put a property in the master page that in turn sets a
    property on its user control that then sets the label controls text.

    And also have the button web control raise an event when the status
    changes and in its pages handler for that call the master pages
    property let.

    That way the interaction is between the control and the page, the page
    and it's master, and the master and it's control, and not directly
    between the two controls.


    So in the button user control

    Public Event StatusChanged(ByVal s As String)
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    RaiseEvent StatusChanged(Guid.NewGuid.ToString)
    End Sub

    And in the page that contains it.

    Protected Sub WebUserControl1_StatusChanged(ByVal s As String)
    Handles WebUserControl1.StatusChanged
    Dim mp As TheMasterPage = Me.Master
    mp.NewStatus = s
    End Sub

    And in the master page.

    Public WriteOnly Property NewStatus() As String
    Set(ByVal value As String)
    WebUserControl2_1.StatusText = value
    End Set
    End Property

    And in the label user control.

    Public WriteOnly Property StatusText() As String
    Set(ByVal value As String)
    Label1.Text = value
    End Set
    End Property


    It may seem like a lot of code up front but going forward any page can
    set the status with just this.

    Dim mp As TheMasterPage = Me.Master
    mp.NewStatus = "Whatever"

    This will have to be changed to use an interface that all master pages
    implement if you ever get around to wanting to change the master page
    of the site on the fly.
     
    MikeS, Nov 13, 2006
    #2
    1. Advertising

  3. Kiran More

    Kiran More Guest

    Re: Accessing USER CONTROL which is inside Masterpage...

    Hi Mike,

    Thanks a lotttttttttttt......
    really great...


    thanks again....

    kiran more
     
    Kiran More, Nov 14, 2006
    #3
    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. Marco Antonio Montalvo Durán
    Replies:
    2
    Views:
    4,236
    Matt Morris
    Jan 23, 2004
  2. nail
    Replies:
    0
    Views:
    1,584
  3. qwerty
    Replies:
    3
    Views:
    9,329
    Scott Allen
    Sep 30, 2004
  4. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    609
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  5. Leeor Chernov
    Replies:
    2
    Views:
    809
    Leeor Chernov
    Oct 16, 2005
Loading...

Share This Page