1

I have a .aspx page that contains a hidden panel that I need to display from a .ascx control.

On my .Click event from my button on my .ascx I have the following:

Dim myControl2 As Control = FindControl("Content1")
Dim myControl3 As Control = FindControl("keywordSearchModal")

On my .aspx I have the following:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentHolder" runat="server">

    <asp:Panel ID="keywordSearchModal" runat="server" Width="800px" Visible="true">
        This is your modal
        <asp:Button ID="OKButton" runat="server" Text="Close" />
    </asp:Panel>

</asp:Content>

Both myControl2 and myControl3 contain nothing when the button is clicked.

How can I find this control from the .ascx that also happens to be an updatepanel.

UPDATE

I was able to find the control by doing the following:

Dim myPanel As Panel = Page.Master.FindControl("ContentHolder").FindControl("keywordSearchModal")
myPanel.Visible = False

Dim myControl As Control = Page.Master.FindControl("ContentHolder").FindControl("keywordSearchModal")
myControl.Visible = False

I was able to use the ContentPlaceHolderID - However now I can't change the visibility...

UPDATE II

thanks to the suggestion below I was able to capture the button click on my .aspx page. However, now just like before I can't seem to manipulate the control. In this example adding text to the panel.

Protected Sub SearchStart(ByVal sender As Object, ByVal e As EventArgs) Handles EquipmentDetails1.SearchStart
    Dim newLabel As New Label
    newLabel.Text = "This is a label!"

    keywordSearchModal.Controls.Add(newLabel)
End Sub

Thoughts?

webdad3
  • 8,893
  • 30
  • 121
  • 223
  • Check the source... I think you may find that Content1 is not rendered it's just a marker so that the system knows which content is placed into a particular content holder. – Mych Mar 05 '15 at 16:00
  • Ok... What is your aim? I think you maybe going about this the wrong way. – Mych Mar 05 '15 at 16:53
  • @Mych In my .ascx page I have an updatepanel with a button. I want that button to show a panel that is located on the .aspx page (which contains the updatepanel). The .ascx is a child of the .aspx. Does that make sense? – webdad3 Mar 05 '15 at 17:04
  • OK... So what you need in your UserControl ascx page is a bubble-up of the event for the button it contains. What that does is pass-on the button click event to the containing page. Your containing aspx page will have code that will be handled by the bubbled up event and in this code you would show whatever panel you need. Search for bubble-up events and you should find examples... – Mych Mar 05 '15 at 17:13
  • As a side note, you may want to look into these (http://stackoverflow.com/q/4955769/16391) ways to find controls on an asp.net page. Its much less to type. – StingyJack Mar 05 '15 at 18:53

1 Answers1

1

Here is what I've used in the past...

My user control has an imagebutton and the following in the codebehind

    Public Event SearchStart As EventHandler
    'This will be the event triggered when the imagebutton is clicked 

    Protected Sub ib_Search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ib_Search.Click

        'Bubble up event to parent
        RaiseEvent SearchStart(Me, e)

    End Sub

Any page that uses the User Control will have the following in codebehind...

    Protected Sub mc_SearchFilter_SearchStart(ByVal sender As Object, ByVal e As EventArgs) Handles mc_SearchFilter.SearchStart

        'CODE that needs to be executed when search image button is clicked in my_control_SearchFilter

    End Sub

Hope that helps....

Mych
  • 2,527
  • 4
  • 36
  • 65