Results 1 to 8 of 8

Thread: aspnet page and a custom control on that page

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,478

    aspnet page and a custom control on that page

    I have an asp.net pagel called UserApproval.aspx. On that page is a custom control ascx. So the order of events is that UserApproval's Page_Load is called, then the ascx's Page_Load is called. The ascx page might discover a problem and can't render what it needs to render (if the user isn't authorized). It has no problem hiding some of the web controls on it, but I would also like to hide some of the web controls on the parent/UserApproval page. Am I able to do this?

    For example, the parent page displays instructions about clicking a button. But the buttons are built by the custom control if the user is authorized to see the buttons. If he can't, can I change or hide the parent's instructions?

    Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: aspnet page and a custom control on that page

    set up public properties for the control and then control everything via the page laod of the aspx page.

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,478

    Re: aspnet page and a custom control on that page

    Is that the only way? I didn't want to rearchitect the whole page. If the answer is "No, the custom control can't change or hide controls on the parent page", I will just present the instructions anyway. The user is given a message that he doesn't have the authority and there is nothing clickable then shown to him, so there is no harm done. I just wanted to make it a little bit more perfect. Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: aspnet page and a custom control on that page

    You could probably create a public method in the aspx page, and then call this from the usercontrol on page load.

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,478

    Re: aspnet page and a custom control on that page

    Thank you. I liked that idea and I am trying it. However, I want to hide a div, and it doesn't seem available to me in the code-behind. Do you know why not?

    Code:
    <div id="approval-introduction" runat="server">
    
    <div class="areaTitle">Document Approval</div>
    <div class="areaComment" style="margin: 0px 0px 15px 0px;">Documents are listed below</div>
    
    <p>blah blah blah</p>
    
    <p>blah</p>
    
    </div>
    I have compared this to other code where I have a div and *can* access it from the code-behind. I am not sure what the difference is.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  6. #6

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,478

    Re: aspnet page and a custom control on that page

    Okay, disregard that last question. I stripped everything out except the div, then I had access to it in the code-behind. I gradually added elements back in until eventually all elements were added back in, and I still have access to it in the code-behind. Whatever.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  7. #7

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,478

    Re: aspnet page and a custom control on that page

    So now this is my code in the parent page:
    Code:
        Public Sub HideInstructions()
    
            approval_introduction.Visible = False
    
        End Sub
    But HideInstructions() is not exposed to the control page.

    And anyway, isn't the parent page already rendered - so how can I change anything on it from the control page? I am not sure what I am asking to do is even possible.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: aspnet page and a custom control on that page

    Quote Originally Posted by MMock View Post
    So now this is my code in the parent page:
    Code:
        Public Sub HideInstructions()
    
            approval_introduction.Visible = False
    
        End Sub
    But HideInstructions() is not exposed to the control page.

    And anyway, isn't the parent page already rendered - so how can I change anything on it from the control page? I am not sure what I am asking to do is even possible.
    Oh, it's you.


    That way won't work well due to the lifecycle. You want to go the other way - have the control raise an event. Have the page subscribe to that event. When the page handles that event, that's when you set the visibility.

    So it'll look something like this. Keep in mind I'm searching and pasting.

    In the ASCX, declare the event:

    Code:
    Public Event HideApprovalDiv()

    Then, from somewhere else in the code,

    Code:
    RaiseEvent HideApprovalDiv()


    Now in your ASPX page, you'll want to handle that event.

    Code:
    Protected Sub MyControl_HideEvent() Handles MyControl1.HideApprovalDiv
    
    'Hide it here
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width